The page "Advanced Scheme: Some Naughty Bits" states:
Continuations are a powerful control-flow construct from which nearly any other control-flow structure [...] may be derived.
I thought that Scheme's call/cc
, being related (*) to Peter Landin's J operator, could be used to implement any known control flow structure?
With "control flow structure" I'm specifically thinking about Wikipedia's description of them, e.g. exceptions, coroutines, green threads and so on.
Specifically, are there any examples of control flow structures that cannot be implemented using call/cc
?
(*) I haven't been able to dig up any paper that establishes that call/cc
is as powerful as the J operator. A paper by Felleisen (which I haven't read and admittedly have problems understanding it fully) investigates this, and seems to conclude that even though they are in different complexity classes, they are formally equivalent.
(Also note that I have updated the question based on the comments below)
Update
Based on the excellent answer by @Neel below, I've looked at sites commenting on delimited and undelimited continuations, and it does indeed seem that while call/cc
, being undelimited, is not sufficient. Meanwhile, first-class, delimited continuations (like shift/reset
) can be used, it seems, to express any control-flow structure.
call/cc
cannot express exceptions in the absence of state. (As Thielecke goes on to point out, exceptions can be implemented by passing around two continuations, one for the program and the other for the exception handler, but that requires more than justcall/cc
.) $\endgroup$amb
-operator, and so on. $\endgroup$