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
aspect oriented computing and scope
-
- Posts: 429
- Joined: Tue Nov 11, 2003 2:11 am
- Location: Brisbane, Australia
-
- Posts: 18
- Joined: Fri Jun 25, 2004 10:57 pm
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.
may be dynamic scoping adds some interesting possibilites but breaking declarative style is too much a cost in my opinion.
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.
the great thing in functional programming is declarative style.It is good to see that somebody has a fresh look at dynamic scoping and points out the interesting possibilites it has.
may be dynamic scoping adds some interesting possibilites but breaking declarative style is too much a cost in my opinion.
-
- Posts: 429
- Joined: Tue Nov 11, 2003 2:11 am
- Location: Brisbane, Australia
I don't see that dynamic scoping of itself breaks declarative style - what's your basisBrickCaster 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.
for saying that?
Nigel
PS thanks for your commenting - my question is to learn.
-
- Posts: 18
- Joined: Fri Jun 25, 2004 10:57 pm
>>
... 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
... 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
-
- Posts: 18
- Joined: Fri Jun 25, 2004 10:57 pm
(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.
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.
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
(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