Explicit renaming
Explicit renaming (ER) macros provide an alternative macro transformer spec that allows a macro to execute the full Scheme language. Note that, unlike The explicit renaming transformer has the following form:
(er-macro-transformer
(lambda ({expression} rename compare) {body})
)
syntax
Expression is the code to be transformed by the macro.
Body is the Scheme code that will be executed when the macro is called, to transform the given expression.
For example, here is an explicit renaming macro
(define-syntax swap!
(er-macro-transformer
(lambda (form rename compare?)
(let (
(x (cadr form))
(y (caddr form))
(%tmp (rename 'tmp))
(%let (rename 'let))
(%set! (rename 'set!))
)
`(,%let ((,%tmp ,x))
(,%set! ,x ,y)
(,%set! ,y ,%tmp))))))
Husk's implementation of explicit renaming macros is based on the paper Hygienic Macros Through Explicit Renaming by William Clinger, which explains them in more detail. |