aspect oriented computing and scope

For the Compleat Fan
Locked
nigelbrown
Posts: 429
Joined: Tue Nov 11, 2003 2:11 am
Location: Brisbane, Australia

aspect oriented computing and scope

Post by 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/
particularly the pdf "Dynamically Scoped Functions as the Essence of AOP"
( http://www.cs.uni-bonn.de/~costanza/dynfun.pdf ).

Nigel

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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
Posts: 18
Joined: Fri Jun 25, 2004 10:57 pm

Post by BrickCaster »

this PDF document describes a minimal Scheme extension for AOP:

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.
It 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
Posts: 429
Joined: Tue Nov 11, 2003 2:11 am
Location: Brisbane, Australia

Post by nigelbrown »

BrickCaster wrote:
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
Posts: 18
Joined: Fri Jun 25, 2004 10:57 pm

Post by BrickCaster »

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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

>>
... 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
Posts: 18
Joined: Fri Jun 25, 2004 10:57 pm

Post by BrickCaster »

(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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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

Locked