A 'continuation' is the entire future of a computation. Every point in a computation has a continuation which, in naive terms, you can think of as the current program-counter and current stack. The Scheme call/cc
function conveniently captures the current configuration and packages it up into a function. When you invoke that function you revert back to that point in the computation. Thus, a continuation is very different from a function (but the continuation function is, well, a function).
There are two common cases where one typically sees call/cc
applied:
non-local exit. You establish a continuation, do some computation, to abruptly end the computation you invoke the continuation.
restart/reenter a computation. In this case you save the continuation and then call it again as you please.
Here is an example for case #1:
(begin
;; do stuff
(call/cc (lambda (k)
;; do more
;; oops, must 'abort'
(k 'ignore)))
;; continue on
)
And here is an example for case #2:
> (define c #f)
> (let ((x 10))
(display (list (+ 1 (call/cc (lambda (k) (set! c k) x))) 111))
(display " more"))
(11 111) more
> (c 20)
(21 111) more
> (c 90)
(91 111) more
For this case #2 is it worth noting that the continuation brings you back to the top-level read-eval-print loop - which gives you a chance to re-invoke the continuation in this example!