[Python-Dev] Explicit Lexical Scoping (pre-PEP?)
Talin
talin at acm.org
Mon Jul 10 01:51:45 CEST 2006
Talin wrote:
> Some alternatives:
>
> use x
> using x
> with x -- recycle a keyword?
> reuse x
> use extant x
> share x
> common x
> same x
> borrow x
> existing x
>
> Although, to be perfectly honest, the longer this discussion goes on,
> the more that I find that I'm not buying Guido's argument about it being
> better to define this at the point of use rather than at the point of
> definition. I agree with him that "point of use" is more Pythonic, but
> I'm also beginning to believe that there are some good reasons why many
> other languages do it the other way.
>
> Part of the reason why its so hard to name this feature is that it's
> real name is something like "Hey, Python, you know that cool funky thing
> you do with defining variables in the same scope as they are assigned?
> Well, don't do that here."
(Followup to my own comment)
There are really 3 places where you can indicate that a variable is to
be reused instead of redefined: 1) The point of definition in the outer
scope, 2) A declaration in the inner scope, and 3) The actual point of
assignment.
#1 is what I've been pushing for, #2 is what most of the discussion has
been about, #3 has been talked about a little bit in the context of an
augmented assignment operator.
I actually like #3 a little better than #2, but not with a new operator.
I'm thinking more along the lines of a keyword that modifies and
assignment statement:
rebind x = 10
Other possible keywords are: modify, mutate, change, update, change, etc...
My gut feeling is that most code that wants to use this feature only
wants to use it in a few places. A good example is fcgi.py (implements
WSGI for FastCGI), where they use a mutable array to store a flag
indicating whether or not the headers have already been sent.
-- Talin
More information about the Python-Dev
mailing list