Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Coroutines

6 views
Skip to first unread message

Philippe Lorin

unread,
Mar 21, 2006, 2:34:41 PM3/21/06
to
I need coroutines (actually, a similar construct based on them). I'd
have thought finding a coroutine package for Lisp would be easy, but
after a lot of research, the only example I could find is in ELisp [1]
(despite much talk about coroutines pointing to Lisp or Scheme). I
should be able to tanslate it, or come up with my own scheme, but I'm
surprised by the lack of a standard (be it only de facto). Did I miss
something, or are coroutines just another thing not standardized because
it's "so easy" to implement yourself?

Anyway, any suggestions for implementation are welcome. What I want to
do precisely is something like this (this is an ideal example):

(defcorout spit-letters ()
(print 'a')
(yield)
(print 'b'))

(setf running-coroutine (start spit-letters))
(funcall running-coroutine) => a ; no return value
(funcall running-coroutine) => b ; no return value

(defcorout spit-numbers-and-letters (x)
(print x)
(yield)
(incf x)
(print x)
(incf x)
(spit-letters)
(yield)
(print x))

(setf running-coroutine (start spit-numbers-and-letters 3))
(funcall running-coroutine) => 3 ; no return value
(funcall running-coroutine) => 4 a ; no return value
(funcall running-coroutine) => b ; no return value
(funcall running-coroutine) => 5 ; no return value

[1] http://www.emacswiki.org/cgi-bin/wiki/coroutine.el

Thomas Atkins

unread,
Mar 21, 2006, 2:37:36 PM3/21/06
to
It's not exactly a coroutine library but Arnesi (www.cliki.net/arnesi)
contains a cps, you could probably build coroutines on top of that.

Thomas Atkins

unread,
Mar 21, 2006, 2:38:27 PM3/21/06
to
It's not exactly a coroutine library but Arnesi (www.cliki.net/arnesi)
contains a cps convertor, you could probably build coroutines on top of
that.

ramu...@gmail.com

unread,
Mar 21, 2006, 2:47:41 PM3/21/06
to
It's in scheme, but it should be straitforward to translate to lisp

http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme-Z-H-15.html#node_sec_13.4

Pascal Bourguignon

unread,
Mar 21, 2006, 2:58:34 PM3/21/06
to
Philippe Lorin <palpal...@gmail.com> writes:

> I need coroutines (actually, a similar construct based on them). I'd
> have thought finding a coroutine package for Lisp would be easy, but
> after a lot of research, the only example I could find is in ELisp [1]
> (despite much talk about coroutines pointing to Lisp or Scheme). I
> should be able to tanslate it, or come up with my own scheme, but I'm
> surprised by the lack of a standard (be it only de facto). Did I miss
> something, or are coroutines just another thing not standardized
> because it's "so easy" to implement yourself?

Usually, CL implementations directly jump to threads.
If you aren't using clisp, try threads!


> Anyway, any suggestions for implementation are welcome. What I want to
> do precisely is something like this (this is an ideal example):

Coroutines are easy to implement with continuations. Perhaps you
should have a look at the continuations implementation in arnesi
(UCW).


--
__Pascal Bourguignon__ http://www.informatimago.com/
Litter box not here.
You must have moved it again.
I'll poop in the sink.

Kalle Olavi Niemitalo

unread,
Mar 21, 2006, 3:36:16 PM3/21/06
to
"ramu...@gmail.com" <ramu...@gmail.com> writes:

> It's in scheme, but it should be straitforward to translate to lisp
>
> http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme-Z-H-15.html#node_sec_13.4

That code uses call/cc (aka call-with-current-continuation),
which is neither included in Common Lisp nor trivial to add.

Sashank Varma

unread,
Mar 23, 2006, 9:33:59 PM3/23/06
to
Philippe Lorin wrote:
> I need coroutines (actually, a similar construct based on them).

My memory is that a nice and simple coroutine package is developed in:

http://www.amazon.com/gp/product/0898596092/103-9237248-9447858?v=glance&n=283155

Sashank

0 new messages