[racket] Survey of Syntax and Hygienic Macro Systems?

From: Eli Barzilay (eli at barzilay.org)
Date: Wed Sep 22 16:15:46 EDT 2010

On Sep 21, Will M. Farr wrote:
> John,
> I know this isn't the survey you asked for, but rather one data
> point in such a survey; nevertheless, I hope it's interesting.  Have
> a look at OCaml's Camlp4: a macro language where people sometimes
> *actually* use the AST to write transformations (sometimes
> quotations just won't cut it).  As somebody who has tried to use
> camlp4 before, I can understand the attraction of sexp syntax for
> the language; the OCaml analog of quasiquote is *much* more
> complicated, as is the pattern matching on syntax, as is....

It's much more than just complicated quasiquotes (which I don't even
consider to be a major problem with camlp4).  One problem is that the
AST definition has a different type for each and every different kind
of expression/pattern/type/etc -- and the result is that for even
simple transformations you need to write a whole bunch of boilerplate.
(And to make things less convenient, this giant piece of code is a
single recursive scan, so you need to define it all in a single `let
rec'.)  Worse, at least at the time that we were using it, every OCaml
release meant changes to some parts of the syntax, which means that
all your files are now broken and need to be fixed, which means that
almost anything you write code for becomes very version specific.

But probably worse than all of the above is the fact that there are
different types of syntax objects used for expressions, patterns, and
toplevel expressions.  For an implementation of a lisp-like defmacro
thing for ocaml, I had one attempt to deal with it by converting
everything to sexpr-like values, applying all of the macros on the
result, then convert it back to ocaml syntaxes.  This was too limited,
so a followup attempt was to have one kind of macro definition for
expressions, one for patterns, and one that was working on both but
limited on the kind of syntaxes that are in both.

So I'd say that if anything, using camlp4 is a good demonstration for
how sexprs make life easier.

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the users mailing list.