[Python-Dev] Re: Dynamic nested scopes
Guido van Rossum
Thu, 02 Nov 2000 01:10:57 -0500
> Moshe's explanation of "dynamic scope" is the definition I've seen in
> every programming language text I've ever read. The essence of the
> defintion, I believe, is that a free variable is resolved in the
> environment created by the current procedure call stack.
Ah. The term "free variable" makes sense here.
> I think it muddles the discussion to use "dynamic scope" to describe
> acquistion, though it is a dynamic feature.
> Python using dynamic scope for exceptions. If any exception is
> raised, the exception handler that is triggered is determined by the
> environment in which the procedure was called.
Then I think this is also muddles the discussion, since the look for
exception handlers has nothing to do with free variable lookup.
> There are few languages that use dynamic scoping for normal name
> resolution. Many early Lisp implementations did, but I think all the
> modern ones use lexical scoping instead. It is hard to write modular
> code using dynamic scope, because the behavior of a function with free
> variables can not be determined by the module that defines it. Not
> saying it isn't useful, just that it makes it much harder to reason
> about how a particular modular or function works in isolation from the
> rest of the system.
I think Python 3000 ought to use totally static scoping. That will
make it possible to do optimize code using built-in names!
--Guido van Rossum (home page: http://www.python.org/~guido/)