[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: continuations and threads

This page is part of the web mail archives of SRFI 18 from before July 7th, 2015. The new archives for SRFI 18 contain all messages, not just those from before July 7th, 2015.



> 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