[IronPython] Hosting IronPython 2.X in .NET app
t-jlee at microsoft.com
Tue Jul 10 21:59:24 CEST 2007
> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-
> bounces at lists.ironpython.com] 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* <curt at hagenlocher.org
> > <mailto:curt at hagenlocher.org>> wrote:
> > On 7/10/07, *Dino Viehland* < dinov at exchange.microsoft.com
> > <mailto:dinov at exchange.microsoft.com>> wrote:
> > Major things we know we still have to do include yield
> > expressions (sorry, there's probably a technical term for
> > 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:
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:
x = 5
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.
SDE Intern, Dynamic Language Runtime
<t-jlee at microsoft.com>
More information about the Ironpython-users