[Python-Dev] Re: Dynamic nested scopes
Thu, 2 Nov 2000 11:36:45 -0500 (EST)
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.
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.
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.