Created
April 24, 2014 22:03
-
-
Save ijp/11271062 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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