[erlang-questions] callcc or CPS in Erlang?

Jachym Holecek freza@REDACTED
Thu Jul 28 15:20:53 CEST 2011

# Jon Watte 2011-07-28:
> It sounds like what you want is just a way to create a closure, not "CPS" per se. Continuation
> Passing Style is a specific approach to slice workloads into separate function invocations;

I suppose you're aware of this, but for precision's sake: the point of CPS is
to convert each and every instance of each and every form of control transfer
into a tail function call -- it's neccessarily a global transformation. What
this thread seems to be about would better be described as "callback-driven"
approach, or "CPS inspired" perhaps -- not CPS itself.

> one use of which is to implement a poor man's threading system.

Yes, emulating scheduler activities manually is indeed poor man's threading.
There's nothing poor about using real CPS as a foundation of concurrency
implementation (Isn't this what at least GHC's LLVM backend is doing? And
it sure is precisely how things work in Gambit-C Scheme.) -- though I'm
sure there are challenges along the way the extent of which I can't really

As you note, concurrency is just one use of CPS. On the other hand, one
can implement perfectly good first-class continuations without CPS (even
in C actually -- makecontext(3) and friends -- which is about what N:M
thread implementations must have been doing under the cover).

Anyway, could not resist...

	-- Jachym

More information about the erlang-questions mailing list