Guido van Rossum wrote: > On 6/30/06, Ka-Ping Yee <[EMAIL PROTECTED]> wrote: >> On Fri, 30 Jun 2006, Andrew Koenig wrote: >>> I hope Py3000 has lexical scoping a la Scheme... >> Me too -- that would be really nice. > > That's not a very constructive proposal (especially since I don't know > Scheme). Perhaps you could elaborate on what needs to change?
I believe the essence of their request for lexical scope boils down to allowing rebinding. Such code like the following is legal in Scheme: def f(x): def incr(): x = x + 1 return x def decr(): x = x - 1 return x return (incr, decr) (incr, decr) = f(1) print incr() # 2 print incr() # 3 print decr() # 2 print decr() # 1 -- FWIW, the Scheme equivalent would be something like: (define f (lambda (x) (list (lambda () (set! x (+ x 1)) x) (lambda () (set! x (- x 1)) x)))) (let ([fs (f 1)]) (let ([incr (car fs)] [decr (cadr fs)]) (display (incr)) (newline) ; 2 (display (incr)) (newline) ; 3 (display (decr)) (newline) ; 2 (display (decr)) (newline))) ; 1 As a more personal aside, I can't imagine where I would use this in any python program I have ever wrote. I actually never noticed that rebinding wasn't allowed until recently. -- Scott Dial [EMAIL PROTECTED] [EMAIL PROTECTED] _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com