[Python-ideas] Tweaking closures and lexical scoping to include the function being defined

Spectral One ghostwriter402 at gmail.com
Tue Sep 27 05:53:26 CEST 2011


On 9/26/2011 9:48 PM, Guido van Rossum wrote:
> On Mon, Sep 26, 2011 at 7:43 PM, Nick Coghlan<ncoghlan at gmail.com>  wrote:
>> Despite what I wrote earlier in the thread, I don't think we actually
>> need to declare the idea *dead* if you don't currently like 'nonlocal'
>> as the keyword. Perhaps the 'nonlocal' idea will grow on you (it
>> certainly did on me, the longer I considered the idea), or perhaps you
>> or someone else will come up with an appropriate keyword that everyone
>> considers reasonable.
> Sorry, from reading the responses, the objection that the other use of
> nonlocal refers to scope, not lifetime, seems pretty common, and I
> don't think it will go away. You might as well use "def var = expr" as
> the syntax and justify it by saying that it is clearly defining
> something and syntactically different from function definitions...
>
> OTOH I am happy to let you all bikeshed on a better name.

I was actually considering asking whether using 'def.static' or 
'def.initial' would be a possible way to avoid making a new keyword. I 
honestly prefer def to nonlocal for this. I like that "our" is short, 
but while it's less confusing, I don't see is as clear.

Questions on options:
    Could there be an importable "function" that, when used, declares a 
variable to be one of these?
    Could the keyword be toggled in or out of namespaces based on, say, 
an imported module? If so, the keyword wouldn't be terribly burdensome.

The following could also add to Nick's list of keyword options:
  init (or Initial or even initialize) retain hold held persist preserve 
keep kept lasting stash survive ark reshiyth

Given the frequency of the use case, clarity probably trumps concerns 
about keyword length.
To my eye, those all seem more congruous than "nonlocal."

(Nick's list:
nonlocal once static persistent shared closure own atdef deftime)

-Nate



More information about the Python-ideas mailing list