[Python-Dev] Re: closure semantics

Guido van Rossum guido at python.org
Thu Oct 23 23:40:52 EDT 2003


> Well, the listed variables are "global" to the current local scope.
> I find the rename argument a bit specious.  If I rename a function I
> have to change all the references to it today.  This is just one
> more.  Since "global" is a declarative statement, the compiler can
> tell you immediately that it can't find the old function name.

Right, I tend to agree.

>     Guido> I saw a variant where the syntax was
>     Guido>     'global' vars 'in' 'def'
>     Guido> which solves that concern (though not particularly elegantly).
> 
> I don't see how that can work though.  What does 'def' mean in this
> case?  There can be multiple lexically enclosing functions, any of
> which have the same local variable x which you might want modify.

Yeah, but usually that's not a problem.  The compiler knows about all
those x-es, and uses the innermost (nearest) one.  This matches what
it does when *referencing* a non-local variable, which doesn't need a
global statement.

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list