Dynamical scoping

Kay Schluehr kay.schluehr at gmx.net
Tue Jan 15 04:47:16 EST 2008


On 15 Jan., 02:13, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> George Sakkis <george.sak... 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