yilin.wei10
2020-10-29 01:47:55

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


yilin.wei10
2020-10-29 01:48:10

Drat, the formatting is horrible.


yilin.wei10
2020-10-29 01:49:15

; ~/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)


sorawee
2020-10-29 02:09:57

I suspect that you are using syntax-parameterize incorrectly.


sorawee
2020-10-29 02:10:19

syntax-parameterize should be a part of the template.


sorawee
2020-10-29 02:10:28

That is, you need to put it inside #'.


sorawee
2020-10-29 02:13:13

Here’s an example adapted from the doc


sorawee
2020-10-29 02:13:17

#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)


sorawee
2020-10-29 02:13:51

Notice that syntax-parameterize is quoted under #'


yilin.wei10
2020-10-29 02:28:16

Oh that’s interesting; does it still happen during the same phase?