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

Nick Coghlan ncoghlan at gmail.com
Wed Sep 28 12:15:23 CEST 2011


On Tue, Sep 27, 2011 at 10:18 PM, Stephen J. Turnbull
<stephen at xemacs.org> wrote:
> Paul Moore writes:
>
>  > On 27 September 2011 18:03, Nick Coghlan <ncoghlan at gmail.com> wrote:
>  > > If we're going to settle for a term with multiple meanings, then I
>  > > still think 'nonlocal' is the one that makes the most sense:
>  > > - it's already a keyword
>  >
>  > To be honest, I think you need to stop raising this. You're right, and
>  > it's certainly a lot easier to accept reusing an existing keyword than
>  > adding a new one. But you need to convince people that "nonlocal" is
>  > right, not that it's easier. You're at risk of giving a distinct "I've
>  > got a hammer so it must be a nail" impression here...
>
> As I read Nick, that is *precisely* the impression he *wants* to give:
> "if this ain't a nail in da fust place, it don't need no hammerin'
> nohow".

Indeed, although there was also a teensy bit of hyperbole involved :)

Arnaud and Paul's examples have persuaded me that embedding this
inside the function isn't a good idea, though:

x = 42
def f():
   # Folded by editor (or even just mentally)
assert x == 42 # May fail!

def f():
    statelocal x = 1
    x =1

We'd been considering the latter as arguably tolerable all the way
through, but the combination with making the function body relevant
when understanding the effect of def statements on the scope that
contains them was enough to tip the balance for me.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-ideas mailing list