[IronPython] bug with closure in coroutine

Ronnie Maor ronnie.maor at gmail.com
Wed Jan 27 20:56:33 CET 2010


welcome. pleasure doing business with you :-)

On Wed, Jan 27, 2010 at 8:08 PM, Dino Viehland <dinov at microsoft.com> wrote:

>  It’s so easy to fix it’s actually already fixed for 2.6.1 J  Thanks for
> reporting it though.
>
>
>
> *From:* users-bounces at lists.ironpython.com [mailto:
> users-bounces at lists.ironpython.com] *On Behalf Of *Ronnie Maor
> *Sent:* Wednesday, January 27, 2010 8:17 AM
> *To:* Discussion of IronPython
> *Subject:* [IronPython] bug with closure in coroutine
>
>
>
> Hi IronPython team,
>
>
>
> Seems IronPython 2.6 has some problems with compiling coroutines that
> contain closures:
>
>
>
> tmp.py:
>
> def coroutine():
>
>     x = yield 3
>
>     def inner():
>
>         print 'x=',x
>
>     inner()
>
>
>
> c = coroutine()
>
> c.next()
>
> c.send(10)
>
>
>
> with CPython:
>
> C:\Temp>python tmp.py
>
> x= 10
>
> Traceback (most recent call last):
>
>   File "tmp.py", line 9, in <module>
>
>     c.send(10)
>
> StopIteration
>
>
>
>
>
> with IronPython 2.6:
>
> C:\Temp>ipy tmp.py
>
> Traceback (most recent call last):
>
>   File "tmp.py", line 7, in tmp.py
>
> TypeError: Unable to cast object of type
> 'Microsoft.Scripting.Ast.FieldExpression' to type
> 'Microsoft.Scripting.Ast.BlockExpression'.
>
>
>
>
>
> workarounds:
>
> 1) re-assign the result returned from yield to another variable
>
> def coroutine():
>
>     tmp_x = yield 3
>
>     x = tmp_x
>
>     def inner():
>
>         print 'x=',x
>
>     inner()
>
>
>
> 2) pass the value explicitly instead of using a closure
>
> def coroutine():
>
>     x = yield 3
>
>     def inner(x):
>
>         print 'x=',x
>
>     inner(x)
>
>
>
> hope it's easy to fix
>
>
>
> thanks
>
> Ronnie
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20100127/a811333b/attachment.html>


More information about the Ironpython-users mailing list