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

Develop an assert procedure

(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 assert (lambda (p) (if (not p) (amb-fail))))

(define f
  (lambda () 
    (let ((a (amb 1 2 3 4 5 6 7)))
      (display 'try:)(display a)(display " ")
      (assert (eq? a 6))
      (display "success: a=")(display a)(newline)
 -  Invoke (f) and watch the program consider all values of a. Using assert instead of back is more pleasing to the eye, especially since these can be piled up in line.