Nested scopes: why is it weird?
Alex Martelli
aleaxit at yahoo.com
Sat Sep 8 18:47:38 EDT 2001
Scott Long wrote:
...
> In this spirit, why not place variables into scopes dynamically as well?
Because it doesn't work well. The original LISP had dynamic scoping, and
it was *by far* the biggest weakness of that otherwise-great language.
Ever since Scheme introduced lexical scoping, Lisp rushed to copy it on
that point, and Common Lisp now scopes lexically -- and works much better
because of that.
> The problem doesn't occur if you associate scopes with suites instead of
> function defs (equivalent to block scopes in C/C++ for example). A suite
> (or block) has a definite "first statement".
Yes, but that granularity would be utterly and totally useless for
determining local variables. If a variable was local to each block that
bound it, you could never modify any variable in a statement guarded by an
if without first artificially accessing the variable to show it's the
"outer" one you mean -- what a nightmare!
Fine-grained scoping can only work hand in hand with declarations, and
Python (thanks be) does not have them.
Alex
More information about the Python-list
mailing list