[Python-Dev] Explicit Lexical Scoping (pre-PEP?)

Ka-Ping Yee python-dev at zesty.ca
Mon Jul 10 23:53:01 CEST 2006


On 7/10/06, Ka-Ping Yee <python-dev at zesty.ca> wrote:
> What's wrong with "nonlocal"?  I don't think i've seen an argument
> against that one so far (from Talin or others).

On Mon, 10 Jul 2006, Jeremy Hylton wrote:
> It's a made-up word.  You won't find it in the dictionary and the
> google define: query sends me to a wikipedia page about quantum
> mechanics.

Two million Google hits for "nonlocal" seems like plenty.
The explanation of "nonlocal" is pretty straightforward --

    If the definition of f() contains an assignment to x, then
    x is a local variable in f, unless x is declared nonlocal.

> To express this email in the positive form:
> 1. Reserved words should be real words.
> 2. The meaning of the word should be clear.
> 3. "Put statements in positive form."  (Strunk & White)
> 4. The word should sound good.
>
> global meets all of these requirements.

But it's the wrong word.  "Purple" also meets all of these requirements.

I'd rather accurately express the concept in the negative (the
true meaning really is in the negative: "don't make a new binding"),
than choose a simple-sounding word that is essentially a lie.

    x = 1

    def f(x):
        print x

        def g():
            global x
            x = 3
            print x

The "x" used in g is not global at all -- it belongs to f.


-- ?!ng


More information about the Python-Dev mailing list