[Python-Dev] PEP for Better Control of Nested Lexical Scopes
Phillip J. Eby
pje at telecommunity.com
Wed Feb 22 19:56:48 CET 2006
At 06:14 AM 2/22/2006 -0500, Jeremy Hylton wrote:
>On 2/22/06, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> > Mark Russell wrote:
> >
> > > PEP 227 mentions using := as a rebinding operator, but rejects the
> > > idea as it would encourage the use of closures.
> >
> > Well, anything that facilitates rebinding in outer scopes
> > is going to encourage the use of closures, so I can't
> > see that as being a reason to reject a particular means
> > of rebinding. You either think such rebinding is a good
> > idea or not -- and that seems to be a matter of highly
> > individual taste.
>
>At the time PEP 227 was written, nested scopes were contentious. (I
>recall one developer who said he'd be embarassed to tell his
>co-workers he worked on Python if it had this feature :-).
Was this because of the implicit "inheritance" of variables from the
enclosing scope?
> Rebinding
>was more contentious, so the feature was left out. I don't think any
>particular syntax or spelling for rebinding was favored more or less.
>
> > On this particular idea, I tend to think it's too obscure
> > as well. Python generally avoids attaching randomly-chosen
> > semantics to punctuation, and I'd like to see it stay
> > that way.
>
>I agree.
Note that '.' for relative naming already exists (attribute access), and
Python 2.5 is already introducing the use of a leading '.' (with no name
before it) to mean "parent of the current namespace". So, using that
approach to reference variables in outer scopes wouldn't be without precedents.
IOW, I propose no new syntax for rebinding, but instead making variables'
context explicit. This would also fix the issue where right now you have
to inspect a function and its context to find out whether there's a closure
and what's in it. The leading dots will be quite visible.
More information about the Python-Dev
mailing list