[Python-ideas] Tweaking closures and lexical scoping to include the function being defined
Paul Moore
p.f.moore at gmail.com
Mon Sep 26 13:45:36 CEST 2011
On 26 September 2011 12:34, Nick Coghlan <ncoghlan at gmail.com> wrote:
> On Mon, Sep 26, 2011 at 2:56 AM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
>> So, your proposed use of 'nonlocal' would actually be declaring
>> a name to be *local*. That strikes me as weird and perverse.
>
> Ah, but it *wouldn't* be local, that's the point - it would be stored
> on the function rather than on the frame, and hence be shared across
> invocations.
Hmm, its lifetime is non-local, but the visibility is still local. My
instincts associate the word "(non-)local" with visibility rather than
lifetime.
If you want a bikeshed to colour in, maybe "persistent" is a better
keyword for this:
def counter():
persistent n as 1
print(n)
n += 1
Paul.
More information about the Python-ideas
mailing list