I'm exploring Scheme macros, but I've been unable to find a portable way of writing anaphoric macros.
I'm trying to write an each-it
macro, such that this code:
(each-it (list 1 2 3)
(display it))
Expands to this:
(for-each (lambda (it)
(display it))
(list 1 2 3))
I've written a macro with syntax-rules
, but this gives me an error about an undefined identifier when I try to use it.
(define-syntax each-it
(syntax-rules ()
((each-it lst body)
(for-each (lambda (it) body)
lst))))
This SO question mentions define-syntax-parameter
, which seems to be Racket only. This blog post gives some Scheme code samples, but the code samples don't run in DrRacket in R5RS
mode (I think it's the square brackets?).
R4RS has an interesting macro appendix but it is not present in R5RS and I don't know if I can depend on it.
Can I write my each-it
macro in a completely portable way? If not, what are the most widely available macro system features for writing my macro?