Created
June 28, 2012 14:02
-
-
Save nyuichi/3011564 to your computer and use it in GitHub Desktop.
Closure Conversion
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 (f) | |
(let ((x 0)) | |
(let ((up (lambda () (set! x (+ x 1)) x)) | |
(dn (lambda () (set! x (- x 1)) x))) | |
(cons up dn)))) | |
(define g (f)) | |
((car g)) ;=> 1 | |
((car g)) ;=> 2 | |
((car g)) ;=> 3 | |
((cdr g)) ;=> 2 | |
((cdr g)) ;=> 1 | |
((car g)) ;=> 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment