

Stackless Python-like coroutines in Scheme. - euccastro

After some time of doing only toy tests and book exercises, I'm getting deeper into Scheme for a real application.  One of the things I missed was Stackless Python's simple to use coroutine API.  In Scheme you have<p>- raw continuations, which I find a bit too wild and low-level for my current purposes, or<p>- full-fledged preemptive threading systems, which seemed way too complex for my needs.  Besides, these are implementation specific, and I didn't want to marry any implementation yet.<p>So I decided to give it a try and roll my own on plain R5RS (I'm sorry it's quite verbose as a result.  I may reduce noise with macros in the future, but this is my first shot at it).  It was easier than I was afraid, and great fun!<p>If you are into Scheme/Lisp, please tell me what you think about it. [Edit: I'm especially interested in comments on the API and semantics. This is more frugal than Stackless's, but I don't miss anything worthy. Do you?]<p><a href="http://pastebin.com/ff732013" rel="nofollow">http://pastebin.com/ff732013</a><p>NOTE: This is just a one day hack; use it at your own risk.  If you are interested in getting future versions of this, just write me at the address in the profile and I'll ping you when I'm confident it's reliable.
======
euccastro
Sorry for keeping talking to myself here, but since this got saved I thought
I'd post a bugfix:

<http://pastebin.com/d631795cd>

My original code was not really R5RS compliant: continuation objects must be
called with exactly one argument, unless the receiving end is explicitly
expecting otherwise. Gambit C didn't complain, but Chicken did. Now this runs
on both.

------
euccastro
A highlighted version so you can avoid the noise on first reading and go
straight to the meat:

<http://pastebin.com/f774fd6c1>

I forgot to add before: if you have questions, I'm eager to reply them. If you
have advice, I'm eager to hear it.

