[Python-3000] Lexical variables at last!

Rocco Orlando Rossi rocco.rossi at gmail.com
Tue Dec 25 23:16:44 CET 2007


I think it's wonderful that Python 3000 will have the nonlocal keyword
allowing complete lexical closures. I've just downloaded Python 3.0 a2 and
tried the following code:

def accumulator(n):

    def foo(x):
        nonlocal n
        n = n + x
        return n

    return foo

... and it works!!! (Now let's see what Paul Graham has to say ... ;) )

However, I've also tried this:

def accumulator(n):
    return lambda x: nonlocal n = n + x

and unfortunately it gave me a syntax error. I don't see any reason why this
kind of code should not be possible.

What do you all think?


-- 
Rocco Rossi

-----------------------------------------------------------------

"Alcuni vedono le cose come sono e dicono perché? Io sogno cose non ancora
esistite e chiedo perché no?"

G.B. Shaw
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-3000/attachments/20071225/8ad0aaea/attachment.htm 


More information about the Python-3000 mailing list