This project is very interesting, and once it's working on sbcl I'd like to dig into it a bit more. Thanks for the good work.
I saw some mention of coroutines in the list archive. I spent some time working on implementing some python-ness in lisp, and have a partially complete code transformer that can make generators and coroutines possible. It's sort of a state machine output; I don't know how it compares to the method mentioned by Ben used by c#. I could make it available if there is interest, and hopefully even complete it :)
Hey Paul, welcome to the list :-)
On 8/10/06, paul cannon paul-clpython@nafpik.com wrote:
I saw some mention of coroutines in the list archive. I spent some time working on implementing some python-ness in lisp, and have a partially complete code transformer that can make generators and coroutines possible.
I'm certainly curious about your work. CLPython fully supports Python's generators except for the fairly new 'yield as expression' feature ("x = yield y"). By tracing function 'rewrite-generator-funcdef-suite you can see how a generator is rewritten into a state machine.
Rewriting of generator's function bodies into the state machine made me feel an assembly programmer: tagbody, goto... :-) Most of the rewrite rules were straightforward, but handling 'yield inside 'try/except correctly required some care.
As for getting it running on SBCL: probably the heavy use of custom declarations of the form "(declare (pydecl ...))" and environment inspection functions, are the hardest issues in making CLPython portable; but I have to admit I looked only briefly at what other implementations offered in this aspect.
- Willem
clpython-devel@common-lisp.net