Re: continuations and threads Marc Feeley 21 Mar 2000 02:35 UTC

> May I ask a heretical question (especially from me):
>
>  How many of you use call/cc and continuation objects
>  (rather than mimicing continuations with lambda's)
>  in large programs? Do "we" really use it to implement
>  coroutines and backtracking and threads and whatever?

I've used call/cc for many things.  Some are fairly standard (like
multithreading, coroutines, exceptions, ...).  My most frequent use is
for non-local exit, for fatal errors.  Perhaps my most unusual use of
call/cc is to translate the "receive" construct of Erlang in my Erlang
to Scheme compiler... the receive form allows waiting until a message
which matches a certain pattern is received in a process' message
queue.  Call/cc is used to grab a continuation at the top of the
translation of receive so that if the pattern match fails, control can
return to that continuation to check if the next message matches the
pattern.  This way of doing a loop avoids the creation of closures,
which would be slower.

>  Is call/cc necessary for Scheme?

Are trunks necessary for elephants?  I am certainly used to the idea.
Call/cc gives unequaled power and flexibility for compiling the
control constructs of other languages into Scheme, which I think is
one of Scheme's most important applications (I have already used
Scheme to compile Erlang, and am now using it to compile Java, and I
know other users of Gambit have done similar compilers).

Marc