[r6rs-discuss] Low-level macro systems (Was: On naming the next scheme(s))
Brian Mastenbrook
brian at mastenbrook.net
Tue Aug 25 11:42:49 EDT 2009
On Aug 25, 2009, at 2:14 AM, Peter Bex wrote:
>> If you're thinking of
>> unhygienic macros, I think this would be a horrible idea; lexical
>> scoping of *all* identifiers, including those in syntax definitions,
>> is central to the Scheme idea.
>
> Not necessarily. I think all low-level systems allow for breaking of
> hygiene, but that's not the reason to prefer a low-level system.
> A low-level system is useful because it allows one to explain macros
> in terms of familiar Scheme primitives as cons, car and cdr.
> This simplicity fits well with Scheme, and I think it would also serve
> well in an educational setting - having to explain that high-level
> macro systems are their own language separate from Scheme is yet
> another
> layer of complexity.
From an implementer's perspective, `syntax-rules' does indeed look
like something that's difficult to explain, but in my experience
having arbitrary code running in the macro-expansion phase raises its
own can of worms. It's very easy for new programmers to get confused
as to what is running when, and what needs to be around for certain
things to happen. `syntax-rules' provides a flexible, easy-to-use
macro system that retains one of the core ideas of the language, that
of static scoping. The idea of template expansion as a means of
metaprogramming is easily explained and avoids the need to discuss
issues of phase.
Additionally, low-level macro systems are a contentious issue, and I
don't believe that the implementor or user has yet settled on any
consensus on the issue. Implementations of the R5RS are still being
developed with a variety of low-level macro systems. It's to the R5RS
user's benefit that a consistent means of hygienic macro definition is
provided by all of these implementations. Rather than scrap `syntax-
rules' in the Thing One language, I'd rather see extensions to `syntax-
rules' standardized and included. SRFI-46 is an obvious candidate for
this as it addresses a fundamental issue in syntax-defining syntax not
accounted for by the R5RS. I also believe that a standard facility for
limited breaking of hygiene could be included which would address a
substantial fraction of the demand for a low-level macro system. I've
sketched out what this might look like here:
http://paste.lisp.org/display/86014
The `define-syntax/identifier-context' ugliness is present because
`syntax-rules' templates do not bind the first element of the template
as a pattern variable, but it's necessary to recover hygienic context
information.
--
Brian Mastenbrook
brian at mastenbrook.net
http://brian.mastenbrook.net/
More information about the r6rs-discuss
mailing list