[E-Lang] Why Not Coroutines? (was: Deadlock-free [was what is good about E?])

Richard greon@best.com
Thu, 19 Jul 2001 21:33:34 -0700


Mark S. Miller writes:
>At 07:02 PM Thursday 7/19/01, Richard wrote:
>>You seem to be saying that coroutines can be used to implement user
>>threading.  No.  *Continuations* (which are provided, eg, by Scheme and
>>Stackless Python) can be used to implement user threading.  You mean
>>"continuations".
>
>You imply that it's possible to provide coroutines without providing 
>continuations.  That may be, but I find it hard to imagine.  What would the 
>API of these coroutine primitives look like?

consider a structured-programming construct   
such that "cor" <list of statements> "roc" is a <statement>
(sort of like "begin" ... "end").

then for example
  cor
    while true do
      print "a";
      resume;
      print "b";
      resume;
      print "c";
      resume;
    end of while
  roc

would print "a" first time it was run, "b" second time, etc.  execution
of a "resume" of course causes the thread of control to exit the
enclosing "cor"-"roc" construct.  sort of like "return"

I'm not advocating such a construct, just exhibiting a way of coding up
a coroutine without explicitly naming a continuation, as you requested.

I did what you asked, right?

a saner example API is given on page 316 of Essentials of Prgmng Languages.
that API consists of procs "resume" and "makecoroutine" and is implemented
in terms of call/cc.  I bet other Scheme books have it, too