Hi! I think the current implementation of `begin-for-syntax` and `define-for-syntax` violate hygiene when used inside macro templates. For examples, if we run: ``` (begin-for-syntax (define (foo) 42)) (begin-for-syntax (display (foo)) (newline)) ``` Both kawa and racket display 42 correctly. But if we modify the program to place `begin-for-syntax` inside a macro templates: ``` (define-syntax install-foo! (syntax-rules () ((_) (begin-for-syntax (define (foo) 42))))) (install-foo!) (begin-for-syntax (display (foo)) (newline)) ``` Racket signals the following error: ``` foo: undefined; cannot reference an identifier before its definition in module: top-level context...: top-level: [running body] ``` but kawa displays 42, violating hygiene. Similar results are obtained if we replace `begin-for-syntax` by `define-for-syntax` or use guile instead of racket. In the case of guile, we need to use `(eval-when (expand load eval) ...)` rather than `begin-for-syntax`. Currently, we can workaround this issue by using `generate-temporaries` and `with-syntax`: ``` (define-syntax install-foo! (lambda (stx) (syntax-case stx () ((_) (with-syntax (((foo) (generate-temporaries #'(foo)))) #'(begin-for-syntax (define (foo) 42))))))) ``` We can even generate an uninterned symbol and then convert it to an syntax object for extra safety if we wish to do so. -- Alex My PGP public key: https://salsa.debian.org/alexvong243f/pgp-key/-/raw/master/A5FCA28E0FF8E4C57F75555CDD66FE5CB79F5A5E.asc