[Python-Dev] nested-scopes redux (fwd)

aahz@panix.com aahz@panix.com
Mon, 17 Sep 2001 00:23:09 -0400 (EDT)


Haven't seen any response to this, and I think it deserves one (then
again, I could be wrong):

------- start of forwarded message -------
From: Cliff Wells <logiplexsoftware@earthlink.net>
Newsgroups: comp.lang.python
Subject: nested-scopes redux
Date: Wed, 12 Sep 2001 15:45:17 -0700
Message-ID: <mailman.1000335016.31172.python-list@python.org>
Reply-To: logiplexsoftware@earthlink.net
To: python-list@python.org

Sorry to bring this subject back up again, but I just noticed a somewhat 
annoying feature of the current nested-scope implementation.  One of the big 
pluses of nested scopes is doing away with default arguments in lambda 
functions.  Unfortunately the following bits of code behave differently:

foo = []
for i in [1, 2]:
    foo.append(lambda i = i: i)

and 

from __future__ import nested_scopes
foo = []
for i in [1, 2]:
    foo.append(lambda: i)

In the first case the output from foo[0]() and foo[1]() is 1 and 2, 
respectively - and it's what one would probably want.  In the second case, 
the output is always 2.  This may be the expected behavior, but it kind of 
does away with the benefits to providing a cleaner lambda call.

-- 
Cliff Wells
Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 x308
(800) 735-0555 x308

------- end of forwarded message -------