[plt-scheme] syntax identifier used out of context
I'm wondering why I get this error from the following code. I was
helping someone on IRC so I don't have a real use case, just wondering
what the error means. If I change bar2 to bar in the template then it
works. Also it seems like I should be able to replace the lambda in
syntax-parameterize by just bar2, but then I get an error about bar2 not
being bound in the transformer environment.
> compile: identifier used out of context in: bar2
#lang scheme
(require scheme/stxparam)
(define-syntax-parameter x (lambda (stx) (error "dont use x")))
(define-syntax bar
(syntax-rules ()
((_ q) (+ 1 q))))
(define-syntax (foo stx)
(define (bar2 stx3)
(syntax-case stx3 ()
((_ q) #'(+ 1 q))))
(syntax-case stx ()
((_ pat) #'(syntax-parameterize ([x (lambda (stx3)
(syntax-case stx3 ()
((_ . q) #'(bar2 . q)))) ])
(begin
(printf "You won ~a!\n" pat))))))
(foo (x 4))