Skip to content

Instantly share code, notes, and snippets.

@nyuichi
Created June 28, 2012 14:02
Show Gist options
  • Save nyuichi/3011564 to your computer and use it in GitHub Desktop.
Save nyuichi/3011564 to your computer and use it in GitHub Desktop.
Closure Conversion
(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