Reputation:
I have the following dumb test:
(define-syntax a
(lambda (stx)
(syntax-case stx ()
[(k e s) #'(let ((show display)) (e s))])))
(a show "something")
Why can't this work? (The error shows in DrRacket is expand: unbound identifier in module in: show
.
However, The following can work:
(define-syntax a
(lambda (stx)
(syntax-case stx ()
[(k e s)
(with-syntax ((show (datum->syntax #'k 'show)))
#'(let ((show display)) (e s)))])))
(a show "something")
Then WHY?
Upvotes: 0
Views: 218
Reputation: 29546
Um, I assume that you're trying this out after reading the blog post I mentioned in an earlier answer -- but that blog post is explaining exactly this issue. Specifically, your first example has two different show
identifiers, one that is bound by the macro, and a different one that is coming from the toplevel use (and is unbound). OTOH, in the second case you're creating a show
with the lexical context of the user code.
Upvotes: 2