As soegaard noted, R. Kent Dybvig. "Three Implementation Models for Scheme" remains the primary reference R. Kent Dybvig. "Three Implementation Models for Scheme" R. Kent Dybvig. "Three Implementation Models for Scheme" R. Kent Dybvig. "Three Implementation Models for Scheme" R. Kent Dybvig. "Three Implementation Models for Scheme" . R. Kent Dybvig. "Three Implementation Models for Scheme"
The idea is that the continuation is a closure that retains its evaluation control stack. The control stack is needed to continue the evaluation from the moment the continuation was created using call/cc .
Often, a continuation call makes the execution time long and fills the memory with duplicate stacks. I wrote this stupid code to prove that the circuit is failing in the mit circuit,
The code sums the first 1000 numbers 1+2+3+...+1000 .
(call-with-current-continuation (lambda (break) ((lambda (s) (ss 1000 break)) (lambda (sn cc) (if (= 0 n) (cc 0) (+ n ;; non-tail-recursive, ;; the stack grows at each recursive call (call-with-current-continuation (lambda (__) (ss (- n 1) __)))))))))
If you switch from 1000 to 100 000, the code will spend 2 seconds, and if the number of input is increased, it will fail.
alinsoar Oct 25 '17 at 8:17 2017-10-25 08:17
source share