[Python-ideas] Before and after the colon in funciton defs.
Guido van Rossum
guido at python.org
Sat Sep 24 02:54:47 CEST 2011
More information about the Python-ideas mailing list
Sat Sep 24 02:54:47 CEST 2011
- Previous message: [Python-ideas] Before and after the colon in funciton defs.
- Next message: [Python-ideas] Before and after the colon in funciton defs.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Fri, Sep 23, 2011 at 5:35 PM, ron adam <ron3200 at gmail.com> wrote: > On Sat, 2011-09-24 at 11:12 +1200, Greg Ewing wrote: >> Ron Adam wrote: >> > On Fri, 2011-09-23 at 11:11 +1000, Nick Coghlan wrote: >> > >> >>Framing the idea that way also suggests a fairly obvious spelling: >> >> >> >> def f(x): >> >> nonlocal i=i # Use 'f' as a closure over *itself* >> >> return x + i >> >> Sorry, but that spelling is very far from obvious to me. >> According to the current meaning of 'nonlocal', it looks like >> a no-op. I don't understand the reasoning that leads from >> there to your proposed semantics. >> >> You'll also have to explain how that reasoning applies to >> the following variations: >> >> nonlocal i = i + i >> nonlocal i = i + j >> nonlocal i = j + k > > > Here's my view of what would happen, but you don't say weather or not > those are defined together or if they are separate cases. > > > nonlocal i > > Gives read write access to i in a parent frame. > > > nonlocal i=i > > Creates a new 'i' in a functions own frame with the value of 'i' from a > parent frame at the time the function is defined. > > (Note, it also makes sense to do it on the first time the function is > called. I'm not sure there is any advantage to that.) > > > Once the function is called, the access of 'i' would be in the local > frame, and not effect the parent frames 'i' because the local 'i' is > found first. > > As for the various cases, they would work the same except the initial > value would be different. The only sensible meaning that could possibly assigned to "nonlocal <var> = <expr>" is that it should be strictly equivalent to nonlocal <var> <var> = <expr> Anything else is too confusing for our users. So your proposal is right out. -- --Guido van Rossum (python.org/~guido)
- Previous message: [Python-ideas] Before and after the colon in funciton defs.
- Next message: [Python-ideas] Before and after the colon in funciton defs.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-ideas mailing list