[IronPython] Hosting IronPython 2.X in .NET app

Sylvain Hellegouarch sh at defuze.org
Tue Jul 10 13:02:54 PDT 2007


Jacob Lee a écrit :
>> -----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
>>>       
>> 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


More information about the users mailing list