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?
An expression's continuation is "the computation that will receive the result of that expression". For example, in the expression (+ 4 (+ 1 2)) the result of (+ 1 2) will be added to 4. The addition to 4 is that expression's continuation.
call/cc (call with current continuation) is a universal control operator (well-known from the programming language Scheme) that captures the current continuation as a first-class object and pass it as an argument to another continuation.
call-in-continuation. let/ cc.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With