[Python-Dev] Using and binding relative names (was Re: PEP for Better Control of Nested Lexical Scopes) (original) (raw)
Steven Bethard steven.bethard at gmail.com
Sun Feb 26 18:17:31 CET 2006
- Previous message: [Python-Dev] Using and binding relative names (was Re: PEP forBetter Control of Nested Lexical Scopes)
- Next message: [Python-Dev] Using and binding relative names (was Re: PEP for Better Control of Nested Lexical Scopes)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 2/25/06, Almann T. Goo <almann.goo at gmail.com> wrote:
On 2/23/06, Steven Bethard <steven.bethard at gmail.com> wrote: > On 2/22/06, Almann T. Goo <almann.goo at gmail.com> wrote: > > def incrementergetter(val): > > def incrementer(): > > val = 5 > > def inc(): > > ..val += 1 > > return val > > return inc > > return incrementer > > Sorry, what way did the user think? I'm not sure what you think was > supposed to happen.
My apologies ... I shouldn't use vague terms like what the "user thinks." My problem, as is demonstrated in the above example, is that the implicit nature of evaluating a name in Python conflicts with the explicit nature of the proposed "dot" notation. It makes it easier for a user to write obscure code (until Python 3K when we force users to use "dot" notation for all enclosing scope access ;-) ).
Then do you also dislike the original proposal: that only a single dot be allowed, and that the '.' would mean "this name, but in the nearest outer scope that defines it"? Then:
def incrementer_getter(val):
def incrementer():
val = 5
def inc():
.val += 1
return val
return inc
return incrementer
would do what I think you want it to[1]. Note that I only suggested extending the dot-notation to allow multiple dots because of Greg Ewing's complaint that it wasn't enough like the relative import notation. Personally I find PJE's original proposal more intuitive, and based on your example, I suspect so do you.
[1] That is, increment the val
in incrementer(), return the same
val
, and never modify the val
in incrementer_getter().
STeVe
Grammar am for people who can't think for myself. --- Bucky Katt, Get Fuzzy
- Previous message: [Python-Dev] Using and binding relative names (was Re: PEP forBetter Control of Nested Lexical Scopes)
- Next message: [Python-Dev] Using and binding relative names (was Re: PEP for Better Control of Nested Lexical Scopes)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]