Closed Zambito1 closed 1 year ago
Code like
(define-syntax foo
(let-syntax ...
(syntax-rules () ...)))
is not valid R7RS(-small). A macro transformer must be of the form (syntax-rules () ...)
and not some arbitrary expression.
Chibi extends it because it offers ER macro transformers (for which there is no formal specification), but the way it implements them, the definition of bar
is only visible to the actual ER transformer (to which syntax-rules
expands), so the identifier bar
in the output does not resolve to the local syntax definition.
It would neither work in a Scheme with a syntax-case system because the identifier bar
would be out of phase.
I must have jumbled up things when I was entering them into my REPL. It turns out my second example
(define-syntax foo
(let-syntax ((bar
(syntax-rules ()
((_ (key . value) ...)
(+ 0 value ...))))
(baz
(syntax-rules ()
((_ (key . value) ...)
(+ 0 key ...)))))
(syntax-rules ()
((_ args ...)
(* (bar args ...) (baz args ...))))))
does not actually work. I thought that was working as I intended which threw me off. Thank you for the explanation.
I believe this is a bug, but please let me know if I'm wrong.
let-syntax
can be used to wrapsyntax-rules
expressions with local macros. For example, the following block:Can be refactored like so, if we are not using
bar
orbaz
outside offoo
:And
foo
will still work the same way. However the following macros work:but using
let-syntax
to packagebar
internal tofoo
does not work:It seems to me like any top level macro of the form:
Should have an equivalent definition of foo: