Is it possible to use https://docs.racket-lang.org/reference/stxparam.html\|syntax-parameterize with syntax/parse? When trying to get the example to work I simply get an error message with unbound identifier; at phase: 1; the transformer environment
; in: syntax-parameterize
Drat, the formatting is horrible.
; ~/Racket/private/stx.rkt:11:10: syntax-parameterize: reference to an unbound identifier
; at phase: 1; the transformer environment
; in: syntax-parameterize
; context...:
; #(3320444 local) #(3320445 intdef) #(3320447 local) #(3320449 intdef)
; #(3320453 local) #(3320454 intdef) #(3320458 local)
I suspect that you are using syntax-parameterize
incorrectly.
syntax-parameterize
should be a part of the template.
That is, you need to put it inside #'
.
Here’s an example adapted from the doc
#lang racket
(require racket/stxparam
(for-syntax syntax/parse))
(define-syntax-parameter it (syntax-rules ()))
(define-syntax (aif stx)
(syntax-parse stx
[(aif test then else)
#'(let ([t test])
(syntax-parameterize ([it (syntax-id-rules () [_ t])])
(if t then else)))]))
(aif 3 it 2)
Notice that syntax-parameterize
is quoted under #'
Oh that’s interesting; does it still happen during the same phase?