
A Scheme syntax-rules primer (2008) - mac01021
http://www.willdonnelly.net/blog/scheme-syntax-rules/
======
neilv
Another one is Joe Marshall's "syntax-rules Primer for the Merely Eccentric":
[http://sites.google.com/site/evalapply/eccentric.txt](http://sites.google.com/site/evalapply/eccentric.txt)

Today, instead of `syntax-rules`, you'll probably use `syntax-case`, which is
a lot easier to use for harder purposes, and also easier error-checking, just
not as interesting as `syntax-rules`. Or, if you're using Racket, `syntax-
parse`.

Greg Hendershott's "Fear of Macros" should be an easy introduction to some of
the newer ways, though it has some Racket-specific bits in it:
[https://www.greghendershott.com/fear-of-
macros/](https://www.greghendershott.com/fear-of-macros/)

~~~
widdershins
I still use `syntax-rules` a lot for simple macros - there's hardly any
boilerplate and macros come out very readable without all the quasi-quoting,
quasi-unquoting etc. that happens in other macro systems.

But some things just can't be accomplished with it. I only turn to `syntax-
case` for these things, like introducing new identifiers, or fully procedural
tasks. It blew my mind when I discovered that I could write a macro that
actually reads files from disk and binds variables to each path at macro-
expansion time (not saying that's a great idea though...)

~~~
neilv
I like `syntax-rules` and have done some crazy things with it. If I were going
to teach someone syntax extension in Scheme or Racket, however, I'd just use
`syntax-case` or `syntax-parse` for everything. That avoids confusing people
with two different languages.

------
camoy
If you're in Racket consider using syntax-parse instead. It's syntax-
rules/syntax-case's more capable cousin:
[https://www2.ccs.neu.edu/racket/pubs/icfp10-cf.pdf](https://www2.ccs.neu.edu/racket/pubs/icfp10-cf.pdf)

------
norswap
Cool! I'd love a follow-up that shows how syntax-rules can do things that are
out of reach for something like the C macro preprocessor.

------
mehrdadn
Confused, why is the macro name necessary when the pattern itself already
specifies the macro name?

~~~
kryptiskt
Making define-syntax bind to a name that appears in the body would be
confusing. You can omit the macro name in the pattern and use an underscore
instead.

~~~
mehrdadn
Does the name have any significance at all? The apparent lack of it is far
more confusing...

------
amirouche
very useful resource, I recommend it.

