Question re local bindings in nested scopes

Mattias Engdegård f91-men at nada.kth.se
Thu Jun 7 06:41:14 EDT 2001


In <3e7e9334.0106062022.2ce58a46 at posting.google.com> goringe at avaya.com (Chris Goringe) writes:

>So, is there an analogue of global for nested scopes?

No, there doesn't seem to be any. This annoys me somewhat, and the
restriction feels arbitrary and stupid for someone used to languages
with real block structure (Scheme, Common Lisp, Perl, Dylan, and even old
Pascal with all its other problems).

PEP-227 (http://python.sourceforge.net/peps/pep-0227.html) discusses this
to some extent but hints on technical problems (without mentioning anything
specific) and that someone called Guido doesn't like it.

It also suggests that classes are a better way to solve it, but I don't
agree: sometimes it is, but often it is much to clumsy to even think of.

For example, when you factor out a common repetitive pattern in a lengthy
subroutine, it is natural to modify the variables in the surrounding scope
since the helper procedure is part of the scope.

The PEP suggest the workaround of using containers which is workable but
confusing to read, and I would say it's against the spirit of python.

If anyone knows what technical problems there would be to implement
rebinding in enclosing scopes, please tell me. Syntactically it could
be done with ":=" as a non-binding assignment operator, or with a new
keyword analoguous to "global", perhaps "nobind", "outer", or "enclosing".




More information about the Python-list mailing list