> -----Original Message----- > From: [EMAIL PROTECTED] [mailto:users- > [EMAIL PROTECTED] On Behalf Of Sylvain Hellegouarch > Sent: Tuesday, July 10, 2007 12:54 PM > To: Discussion of IronPython > Subject: Re: [IronPython] Hosting IronPython 2.X in .NET app > > Curt Hagenlocher a écrit : > > On 7/10/07, *Curt Hagenlocher* <[EMAIL PROTECTED] > > <mailto:[EMAIL PROTECTED]>> wrote: > > > > On 7/10/07, *Dino Viehland* < [EMAIL PROTECTED] > > <mailto:[EMAIL PROTECTED]>> wrote: > > > > Major things we know we still have to do include yield > > expressions (sorry, there's probably a technical term for > them) > > > > Closures :P. > > > > > > Doh! I'm so retarded that I misspelled "generators" :(. > > > > Apparently I've been reading too much about Ruby lately... > > > Not to worry :) > However the question stands, will Python support closures (or does it > already via lambda expressions?) > > (/me is lame at language theory) > > - Sylvain
Closures have existed in Python since version 2.1 or so: def f(): x = 5 return lambda: x closure = f() print closure() # prints 5 Here, the anonymous inner function returned by f is able to refer to variables defined in outer scopes. As for the Python 3000 question -- The one current limitation is that you cannot rebind names defined in outer scopes. That is, the following code does not work as expected: def f(): x = 5 def g(): x = 7 # x is local to g here You could use the "global" statement to indicate that x is a global despite it being assigned to inside the function, but there was no equivalent way to indicate that x refers to a variable in an outer, but non-global, scope. Python 3000 will introduce the "nonlocal" statement that works like the global statement to fill this gap. As usual, the best source is the relevant PEP: http://www.python.org/dev/peps/pep-3104/ Hope this helps. -- Jacob Lee SDE Intern, Dynamic Language Runtime <[EMAIL PROTECTED]> _______________________________________________ users mailing list users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com