Play audio slide show -- Keyboard shortcut: 'x'  Lecture overview -- Keyboard shortcut: 'u'  Previous page: The capturing of continuations -- Keyboard shortcut: 'p'  Next page: Use of continuations for escaping purposes -- Keyboard shortcut: 'n'  Lecture notes - all slides together  Annotated slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Alphabetic index  Help page about these notes  Course home      Name binding, Recursion, Iteration, and Continuations - slide 39 : 42

Capturing, storing, and applying continuations
We here show capturing, imperative assignment, and a subsequent application of a continuation
Context C and expression E

Value of C

Application of continuation

Value

(+ 5 
 (call/cc 
  (lambda (e) 
   (set! cont-remember e)
   (* 4 3))))
17
(cont-remember 3)
8
(cons 1 
 (cons 2 
  (cons 3 
   (call/cc 
    (lambda (e) 
     (set! cont-remember e)
     '())))))
(1 2 3)
(cont-remember '(7 8))
(1 2 3 7 8)
(define x 5)
(if (= 0 x)
    'undefined
    (remainder 
     (* (call/cc 
         (lambda (e) 
          (set! cont-remember e)
          (+ x 1) ))
        (- x 1))
     x))
4
(cont-remember 3)
2