[PRL] hygienic macros

Ryan Culpepper ryanc at ccs.neu.edu
Sun Jul 30 02:43:56 EDT 2006


On Sat, 2006-07-29 at 22:07 -0400, Riccardo Pucella wrote:
> > Has anyone from the syntactically inclined subset in PRL tried to
> > implement (and failed) a macro expander in CαML or Fresh OCAML? I
> > believe that this might shed some light on the nature of hygiene. --
> 
> Interesting question. A while back, I thought about whether nominal logic
> (the formalism underlying C{\alpha}ML and Fresh OCaml could help formalize
> the notion of hygiene. Mitch told me that Dave and him had a look at that a
> while back, and concluded that the framework was inappropriate. I do not
> know the details, however.

Part of the hygiene principle of macro expansion in Scheme---stated very
loosely---requires that an identifier introduced by a macro can only
bind other identifiers introduced in the same macro step.

There is a gap between the expansion of a macro and the discovery of the
roles played by all of the identifiers it introduces, because the
binding forms are only uncovered by the expansion of the macro's output.
Thus these post-introduction, pre-resolution identifiers must be able to
handle a variety of different roles: "As a binding occurrence, I act as
an X.1.5; as a reference I act as an X.1.5, if there is a binding for
X.1.5 in scope; otherwise I act like an X.1, if there is a binding for
X.1 in scope; otherwise I act like an X."

(This situation has been compared to superposition in quantum mechanics.
In fact, Mitch, Dave, and I did prove that this superposition is
necessary to describe Scheme's macro system. Ask me if you're curious.)

In "Macros That Work" by Clinger and Rees, the introduced identifiers
are represented by fresh names, and those names represent the binding-
occurrence meaning of the identifier. The separate syntactic environment
records the meaning of the identifier when used as a reference.

The Dybvig et al system (the one underlying syntax-case) has a more
complex identifier datatype that incorporates that part of the syntactic
environment into the structure of the identifiers. (It also uses a
syntactic environment, but for other things.)

A couple years ago when Matthias and I were looking at the question of
hygiene, I created a little macro calculus that threw away some of the
capabilities of the syntax-case system and used a simpler, yet still
non-atomic identifier structure.

At a workshop last year, I asked Andrew Pitts whether he had thought
about extensions to his theory of atoms and substitution to allow
substitutions of *part* of a name (to support compound names with
timestamps, etc). He answered, "You mean like *molecules*? No, I
haven't."

In summary, you can't do hygiene with atoms. You need either atoms plus
an environment, or molecules.

Ryan

> _______________________________________________
> PRL mailing list
> PRL at lists.ccs.neu.edu
> https://lists.ccs.neu.edu/bin/listinfo/prl




More information about the PRL mailing list