20-CS-4003-001 Organization of Programming Languages Fall 2018
Call-with-current-continuation examples

Lambda calculus, Type theory, Formal semantics, Program analysis

    Prev     Next     All lectures        Code

Put it in a simple program

(define call/cc call-with-current-continuation)

(define amb-fail '())

(define-syntax amb
  (syntax-rules ()
    ((amb x ...)
       (lambda (sk)
           (lambda (fk1)
             (set! amb-fail (lambda () (fk1 'fail)))
             (sk x)))

(define back (lambda () (amb-fail)))

(define f
  (lambda () 
    (let ((a (amb 1 2 3 4 5 6 7)))
      (display a)(display " ")
      (if (not (eq? a 'fail))
 -  Invoke (f) and watch the program consider all values of a.