This question have been asked several times on SO, but none of them solve my question. What is continuation?
Consider the following code:
( (lambda (pair)
(begin (print (car pair))
((cdr pair) (cons (+ 1 (car pair))
(cdr pair)))))
(call/cc (lambda (k)
(cons 0 k))))
This program loops indefinitely printing the sequence of integers starting from 0.
What I understand is:
Step 1: (call/cc (lambda (k) (cons 0 k))) is evaluated, return pair (0 . #continuation) (What is #continuation in here)
Step 2: Apply the pair from step 1 to a lambda function. The lambda function first print out the car, which is 0.
Now, I am totally lost. The program is evaluating (#continuation (1 . #continuation)), which does not really make sense to me. Is #continuation a procedure now?
What makes the program keep applying (call/cc (lambda (k) (cons 0 k))) to the lambda function? So that it can keep calling itself