[Dev] Python dynamic vs lexical scoping
David McCusker
david at osafoundation.org
Fri Nov 15 14:23:55 PST 2002
(For folks who don't understand the difference between dynamic and lexical
scoping of variables, you probably needn't worry about this email. C and
Scheme use lexical scoping, and dynamic is uncommon in modern languages.
But it's still around in things like Emacs' elisp.)
I gather Python 2.2 and later will always have lexical scoping enabled
by default instead of dynamic scoping. I was reading workarounds for
the old dynamic scoping on http://www.hetland.org/python/instant-python.php
and saw the following snippet of code spelling out the transition:
# This magic won't be necessary in Python 2.2:
from __future__ import nested_scopes
If lexical (ie nested) scoping is not already the universal default in
the versions of Python we use, we should probably makes sure all the
Chandler sources ensure lexical scoping it used to avoid odd effects.
Dynamic scoping is not a good fit for programming-in-the-large.
--David McCusker
More information about the Dev
mailing list