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

Lambda calculus, Type theory, Formal semantics, Program analysis

    Prev     Next     All lectures        Code

Put it in a macro

(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)))
 -  Same as the previous slide except a macro allows bringing any size list containing any type of object out to a user. Use it like this:
  >> (define a (amb 1 2 3 4))
  >> a
  ;Value: 1
  >> (back)
  >> a
  ;Value: 2
  >> (back)
  >> a
  ;Value: 3