Skip to content

Instantly share code, notes, and snippets.

@samth
Created April 13, 2017 16:27
Show Gist options
  • Save samth/e1770211d010afa547825e600f7f0279 to your computer and use it in GitHub Desktop.
Save samth/e1770211d010afa547825e600f7f0279 to your computer and use it in GitHub Desktop.
#lang racket
;; not working
(module not-working racket
(define-for-syntax b (box #f))
(define-syntax (pull stx) (unbox b))
(define-syntax (bind stx)
(syntax-case stx ()
[(_ i body)
(begin (set-box! b #'i)
#'(lambda (i) body))]))
(bind x (pull)))
;; working
(module working racket
(define-for-syntax b (box #f))
(define-syntax (pull stx) (unbox b))
(define-syntax (bind stx)
(syntax-case stx ()
[(_ i body)
#'(lambda (i) (with-id i body))]))
(define-syntax (with-id stx)
(syntax-case stx ()
[(_ i body) (begin (set-box! b #'i) #'body)]))
(bind x (pull)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment