aspect oriented computing and scope

Started by nigelbrown, August 08, 2004, 11:23:41 PM

Previous topic - Next topic

nigelbrown

People (newLispers in particular) may be interested in the discussion of

dynamically scoped functions in aspect-oriented programming in lisp.

See http://www.cs.uni-bonn.de/~costanza/">http://www.cs.uni-bonn.de/~costanza/

particularly the pdf "Dynamically Scoped Functions as the Essence of AOP"

( http://www.cs.uni-bonn.de/~costanza/dynfun.pdf">http://www.cs.uni-bonn.de/~costanza/dynfun.pdf ).



Nigel

Lutz

#1
It is good to see that somebody has a fresh look at dynamic scoping and points out the interesting possibilites it has. newLISP implements both (dynamic and lexical) scoping paradigms.



Lutz

BrickCaster

#2
this PDF document describes a minimal Scheme extension for AOP:



http://www.cs.uri.edu/~dbtucker/pubs/aosd2003-tk.pdf">//http://www.cs.uri.edu/~dbtucker/pubs/aosd2003-tk.pdf



thus, dynamic scoping is not necessary to benefit AOP.



the Scheme AOP extension seems more powerful, however i agree it is also far less intuitive because it's based on a continuation-like concept.


QuoteIt is good to see that somebody has a fresh look at dynamic scoping and points out the interesting possibilites it has.


the great thing in functional programming is declarative style.

may be dynamic scoping adds some interesting possibilites but breaking declarative style is too much a cost in my opinion.

nigelbrown

#3
Quote from: "BrickCaster"


the great thing in functional programming is declarative style.

may be dynamic scoping adds some interesting possibilites but breaking declarative style is too much a cost in my opinion.


I don't see that dynamic scoping of itself breaks declarative style - what's your basis

for saying that?



Nigel



PS thanks for your commenting - my question is to learn.

BrickCaster

#4
i mean what you declare is less statically comprehensible because it depends on other dynamic declarations rather than solely on static declarations.

now it's up to you to decide if it's a good thing (more flexible) or a bad thing (less readable).

Lutz

#5
>>

 ... it's up to you to decide if it's a good thing (more flexible) or a bad thing (less readable)

>>



yes, I agree and of course it depends in what circumstances of your code. An easy way to get lexical (and easy recognizable) separation in newLISP is to just prefix certain variable with a context name, i.e.



(set 'Foo:myvar 1234)



You don't need any previous (context ...) statements, to do this anywhere in your code. The name space gets dynamically created just by using it. This also is a tool to quickly 'declare' data structures:



(set 'Person:name "")

(set 'Person:address "")

(set 'Person:balance 0.00)



this prototype object is lexically closed from the outside and you can easy create more of it during runtime:



(new Person 'Lutz)



and then use it:



(inc 'Lutz:balance 1000000)  ;;  please ;-)



serialize it to the disk:



(save "lutz.obj" 'Lutz)



Lutz

BrickCaster

#6
(inc 'Lutz:balance 1000000) ;; please ;-)



many prototype languages (such as NewtonScript) even create the "balance" slot if it is read but do not exist. that's too much flexibility, typos become unnotified, additionnal expressiveness is insignificant :(



one great thing with newLISP contexts is context switching :)



many Scheme implementations have a module extension where module is:



(module

   .....

)



that's not realistic because that favors a batch-mode rather than an interactive mode. module-switching would be better, in a batch file the scope can be visually recreated though indentation.

Lutz

#7
note that context switching in newLISP only switches the context for subsequent symbol  translations:



(set 'x 111)



(define (foo)

  (context 'Ctx)

  (set 'x 222)

  (context 'MAIN))



x => 111

(foo)

x => 222



the context switch had no influence, but:



(set 'x 111)

(context 'Ctx)

(set 'x 222)

(context 'MAIN))



x => 111



Ctx:x => 222



now the context switch happened on the top-level and causes the subsequent symbol to be compiled in to name-space 'Ctx



The context switch only works for subsequent symbol translations:



(set 'x 111)



(define (foo)

  (context 'Ctx)

  (set (symbol "x") 222) ;; or (eval-string "(set 'x 222)")

  (context 'MAIN))



x => 111

(foo)

x => 111

Ctx:x => 222



but I could do this:



(define (foo)

  (set 'old (context))

  (set 'c (context 'CT))

  (context old) ; switch back

  (set 'c:x 999))



(foo)

Cyx:x => 999



The last example shows the possibility to put contexts in to variables. This way you can refer to context variables before they exist



Lutz