In the expression (call/cc (lambda (k) (k 12))), there are three continuations: (k 12), (lambda (k) (k 12)), and (call/cc (lambda (k) (k 12))). Which one is the “current continuation”?
And continuations in some books are viewed as a procedure which is waiting for a value and it will return immediately when it’s applied to a value. Is that right?
Can anyone explain what current continuations are in detail?
Things like
(k 12)are not continuations. There is a continuation associated with each subexpression in some larger program. So for example, the continuation ofxin(* 3 (+ x 42))is(lambda (_) (* 3 (+ _ 42))).In your example, the “current continuation” of
(call/cc (lambda (k) (k 12)))would be whatever is surrounding that expression. If you just typed it into a scheme prompt, there is nothing surrounding it, so the “current continuation” is simply(lambda (_) _). If you typed something like(* 3 (+ (call/cc (lambda (k) (k 12))) 42)), then the continuation is(lambda (_) (* 3 (+ _ 42))).Note that the lambdas I used to represent the “current continuation” are not the same as what
call/ccpasses in (namedkin your example).khas a special control effect of aborting the rest of the computation after evaluating the current continuation.