Skip to content

Instantly share code, notes, and snippets.

@ijp
Created April 24, 2014 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ijp/11271062 to your computer and use it in GitHub Desktop.
Save ijp/11271062 to your computer and use it in GitHub Desktop.
(define-module (angels-and-devils)
#:export (milestone devil angel))
;; See the paper "call-with-current-continuation patterns"
(define future '())
(define past '())
(define-syntax-rule (push var val)
(set! var (cons val var)))
(define-syntax-rule (pop var)
(if (null? var)
(lambda (x) x)
(let ((result (car var)))
(set! var (cdr var))
result)))
(define (milestone x)
(call/cc
(lambda (k)
(push future k)
x)))
(define (devil x)
(call/cc
(lambda (k)
(push future k)
((pop past) x))))
(define (angel x)
((pop future) x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment