Dynamical scoping

G

George Sakkis

What's the best way to simulate dynamically scoped variables ala
Lisp ? The use case is an open-ended set of objects that need to
access the same piece of information (e.g. a dict, a ConfigParser
object, a logger etc.). I know that the "proper" OO and functional way
is to pass the information explicitly but that's less maintenable in
the long run. Also this is in a web environment so the information
can't be really global (though within-thread global should be fine).
Is there some standard pattern for this scenario ?

George
 
P

Paul Rubin

George Sakkis said:
What's the best way to simulate dynamically scoped variables ala Lisp ?

Ugh.... check the docs for the python 2.5 "with" statement, which
gives you sort of a programmable unwind-protect (more powerful than
try/except). You'd have an environment dictionary and use the "with"
statement to maintain a stack of shallow-binding cells like in an
old-time lisp system, automatically unwinding when the "with" suite
finishes. The whole concept sounds hopelessly crufty--I think nobody
even does it that way in Lisp any more, you're better off passing an
environment around explicitly. If there were a lot of variables, this
could be a good application for functional maps, which I've been wanting
to implemetn for python.
 
K

Kay Schluehr

Ugh.... check the docs for the python 2.5 "with" statement, which
gives you sort of a programmable unwind-protect (more powerful than
try/except). You'd have an environment dictionary and use the "with"
statement to maintain a stack of shallow-binding cells like in an
old-time lisp system, automatically unwinding when the "with" suite
finishes. The whole concept sounds hopelessly crufty--I think nobody
even does it that way in Lisp any more, you're better off passing an
environment around explicitly. If there were a lot of variables, this
could be a good application for functional maps, which I've been wanting
to implemetn for python.
 
K

Kay Schluehr

What's the best way to simulate dynamically scoped variables ala
Lisp ? The use case is an open-ended set of objects that need to
access the same piece of information (e.g. a dict, a ConfigParser
object, a logger etc.). I know that the "proper" OO and functional way
is to pass the information explicitly but that's less maintenable in
the long run. Also this is in a web environment so the information
can't be really global (though within-thread global should be fine).
Is there some standard pattern for this scenario ?

George

What do you mean by "really global" and why is module local or builtin
a problem
in the presence of the GIL? Passing objects as parameters into
functions doesn't
ensure any more thread safety. Where do you think does Lisp ( which
one? ) stores
dynamically scoped variables?
 
P

Paul Rubin

Kay, did you have something to add? You quoted the above two posts
and then your message stopped.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top