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

前端 未结 2 1260
失恋的感觉
失恋的感觉 2020-12-28 18:57

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 a

2条回答
  •  执念已碎
    2020-12-28 19:35

    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.

提交回复
热议问题