[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: R5RS interpreters need not apply?

Jeff Dalton writes of Scheme macros:

    There are a lot of subtle issues

Indeed there are.  The main reason I implemented the R4RS high-level
macro system was to understand and document those issues.

    what happens with nested ...s?  If I have a... inside
    another ..., do all the a's get gathered into one "flat" list,
    or is there something like a list of lists?

Something like a list of lists.  It's a little like nested
QUASIQUOTE, where you have to keep track of the nesting depth.

    Also, can I write macro-defining macros, or do the ...s get
    interpreted at the wrong level?

The ellipses can get interpreted at the wrong level.  I propose
an escape syntax such as (::: <template>) to protect ellipses
within <template> from being interpreted at the wrong level.
I have implemented this and it works fine.

    On the other hand, I like Scheme macros, and I want them to
    succeed.  Having people say "they're too expensive", "no they're
    not" doesn't get me any closer to understanding the issues for
    myself.  It would certainly help me, and maybe some others, if
    the people who understand the new macros and feel they can be
    implemented simply and efficiently could explain why this is
    so and how it can be done.

A few rough benchmarks on two thousand lines of code suggest
that my prototype implementation of hygienic macros is about two
or three times as slow as the MacScheme implementation of naive
macros.  I wrote my prototype for clarity, not efficiency.  It
contains several glaring inefficiencies: syntactic environments
are represented as association lists, identifiers are represented
as symbols, and patterns are not fully compiled.  Hygienic macro
expansion will be slower than naive macro expansion, but I think
they will be pretty close after we tune our implementations.

William Clinger