Talin wrote:
> I propose to create a new type of scoping rule, which I will call 
> "explicit" lexical scoping, that will co-exist with the current 
> "implicit" scoping rule that exists in Python today.

I'd like to toss one more variant into the mix.  If we really need to
address variables in an intermediate scope, the most explicit way that I
can think of doing so is to write (using Philip's example):

def counter(num):
    scope as outer # "outer" is an arbitrary identifier
    def inc():
        outer.num += 1
        return outer.num
    return inc

This is somewhat similar to the unworkable "use the function name"
method that's been suggested.  The "scope as X" statement associates the
name "X" with the namespace of local variables in the scope in which it
is executed.  Such names are "lexically scoped", and only allow access
to or rebinding of existing names from the originating scope (i.e. no
"del outer.num" allowed).

Cheers,

Evan @ 4-am

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to