Created
August 8, 2012 14:39
-
-
Save athos/3295528 to your computer and use it in GitHub Desktop.
a solution for SRFI-72's "Improved hygiene" using syntactic closures
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
;; A solution for SRFI-72's "improved hygiene" using syntactic closures. | |
;; See also http://srfi.schemers.org/srfi-72/srfi-72.html#hygiene | |
(let-syntax ([main (sc-macro-transformer | |
(lambda (form env) | |
(define (make-swap x y) | |
`(let ([t ,x]) | |
(set! ,x ,y) | |
(set! ,y t))) | |
`(let ([s 1] [t 2]) | |
,(capture-syntactic-environment | |
(lambda (env) | |
(make-swap (make-syntactic-closure env '() 's) | |
(make-syntactic-closure env '() 't)))) | |
(list s t))))]) | |
(main)) ;=> (2 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment