[Python-Dev] PEP for Better Control of Nested Lexical Scopes
Terry Reedy
tjreedy at udel.edu
Wed Feb 22 20:09:41 CET 2006
"Almann T. Goo" <almann.goo at gmail.com> wrote in message
news:7e9b97090602212336ka0b5fd8r2c85b1c0e914aff1 at mail.gmail.com...
> IMO, Having properly nested scopes in Python in a sense made having
> closures a natural idiom to the language and part of its "user
> interface." By not allowing the name re-binding it almost seems like
> that "user interface" has a rough edge that is almost too easy to get
> cut on.
I can see now how it would look that way to someone who has experience with
fully functional nested scopes in other languages and who learns Python
after no-write nested scoping was added. What is not mentioned in the ref
manual and what I suppose may not be obvious even reading the PEP is that
Python added nesting to solve two particular problems. First was the
inability to write nested recursive functions without the hack of stuffing
its name in the global namespace (or of patching the byte code). Second
was the need to misuse the default arg mechanism in nested functions. What
we have now pretty well fixes both.
Terry Jan Reedy
More information about the Python-Dev
mailing list