Scheme macro systems

[Chicken-users] macro systems and chicken (long), Alex Shinn, Apr 2008.

There seems to be a lot of confusion in the Chicken
community, and the Lisp community in general, about the
different macro systems, so I thought provide some
background information and discussion of the eggs available
in Chicken and their uses.

A very nice post that provides a historical overview and implementations of a hygienic (swap! a b) macro in different macro systems: syntactic closures, reverse syntactic closures, explicit renaming, syntax-case, and syntax-rules.

I didn't know syntactic closures before, and find their interface and implementation simple and easy to understand. Any reasons why they aren't used more in Scheme?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Where do low-level macro facilities hide?

You don't see too much of most of the systems discussed in that link, apart from syntax-case, because they are low-level facilties and so are not much adevrtised to the user, but most scheme systems do have a low-level macro facility (LLMF) lurking somewhere in the background.

This LLMF is usually pretty much Clinger's system from his Hygienic macros through explicit renaming. I'm not really sure why this won out over the Bawden and Rees approach, but I'm guessing that there is some efficiency advantage, and that people feel more comfortable with it due to its closer relationship to Kohlbecker's algorithm.

Shinn's post is very interesting. The advice about understanding hygiene by coding it up explicitly using syntax transformers is, of course, good advice; it's nice to see the advice be followed by examples.

Syntax-case algorithm

I'm not sure what scheme systems are included in 'most', but a significant number of systems have Dybvig's algorithm for syntax-case at the core. Examples here are MzScheme, Chez, Ikarus, and any system that uses portable syntax-case. Andre van Tonder's portable R6RS implementation is also used by a few systems. It's sort of hybrid between syntax-case and explicit renaming.

I believe that the Bawden-Rees syntactic closures algorithm was unable to handle the full complexity of syntax-rules originally, which may have led to the wider prevalence of explicit renaming, at least as an implementation strategy for syntax-rules. As for the low-level systems, I don't think any were implemented that many times.

Poor discussion of syntax-case

Unfortunately, the author's feelings about syntax-case seem to have prevented him for giving a fair overview of its relation to the other systems, and their advantages and disadvantages. For example, he suggests that the relation between syntax-case and syntax is unhygenic, which is untrue.

Also, the idea of having alternate macro systems replaced by changing the expander seems like a really bad idea.