Skip to content

Instantly share code, notes, and snippets.

@athos
Created August 8, 2012 14:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save athos/3295528 to your computer and use it in GitHub Desktop.
Save athos/3295528 to your computer and use it in GitHub Desktop.
a solution for SRFI-72's "Improved hygiene" using syntactic closures
;; 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