lispcomputer-scienceschemecontinuationscallcc

Can call-with-current-continuation be implemented only with lambdas and closures?


Does anyone know if call/cc can be implemented with just lambdas and closures?

It seems that call/cc interrupts the program's flow (like an exception) but lambdas and closures can't do that. Therefore I think call/cc can't be implemented via lambdas and closures.

Any more ideas?


Solution

  • The question is not particularly clear, since what exactly does "implemented with just lambdas and closures" mean?

    In any case, continuations can be used in any language with closures by manually writing in continuation passing style. Then automatic translation into this form can be implemented by extending the compiler, which Lisps typically allow on user level through macros. For example see cl-cont, a library implementing continuations for Common Lisp, which is a language that doesn't have them built in.

    Efficient pervasive continuations like in Scheme are likely to be implemented on a lower level directly dealing with the program stack, but this is not a requirement, just an optimization.