[Dev] Python dynamic vs lexical scoping
Jeremy Hylton
jeremy at alum.mit.edu
Mon Nov 18 05:46:10 PST 2002
>>>>> "DM" == David McCusker <david at osafoundation.org> writes:
DM> Aha, that's very interesting, since it means the explanation
DM> found in http://www.hetland.org/python/instant-python.php is
DM> completely wrong when it says the problem is dynamic instead of
DM> lexical scoping.
I hadn't followed the link until now. (I doesn't take much prompting
to get me to talk about scoping in Python :-). It appears the author
is confused by the special way the top-level namespace is handled (in
almost every lexically scoped language).
DM> Basically, the variables were not free a definition time, but
DM> they became free later because no closure was created to
DM> preserve the bindings from the time a nested function was
DM> created. I'm not sure it's valid to say a language has lexical
DM> scoping when it does this with nested functions, but I suppose
DM> it doesn't really matter.
No, it doesn't really matter. Lexical scoping without nesting means
that a function's globals are determined statically rather than
dynamically. If globals were determined dynamically, you'd pick up
bindings from the module that called the function rather than the
module that defined the function.
Jeremy
More information about the Dev
mailing list