Dynamical scoping

Paul Rubin http
Tue Jan 15 02:13:44 CET 2008

George Sakkis <george.sakkis at gmail.com> writes:
> 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.

More information about the Python-list mailing list