Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 706
bodacydo Avatar asked Sep 28 '10 09:09

bodacydo


People also ask

What is continuation in Scheme?

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.

How does call CC work?

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.

What is call CC in racket?

call-in-continuation. let/ cc.


1 Answers

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.

like image 199
Ramarren Avatar answered Sep 21 '22 17:09

Ramarren