Jacob Lee a écrit : >> -----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. >
Many thanks Jacob. I will admit that I don't often use lambdas in my own code and therefore when asked a straight question aboud them I dodged :) <saving face attempt> That's what I thought of course </saving face attempt> Thanks again. - Sylvain _______________________________________________ users mailing list users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com