[R6RS] SRFI 72 and syntax-case comparison
Matthew Flatt
mflatt at cs.utah.edu
Fri Mar 17 11:25:48 EST 2006
At Mon, 13 Mar 2006 20:09:42 -0500, Anton van Straaten wrote:
> OK, I know my name's not Matthew, but between one thing and another I
> spent some time looking at the SRFI 72 macro proposal. I've written up
> a comparison to syntax-case and put it in Subversion at:
>
> draft/syntax/srfi72-comparison.html
Thanks, Anton!
The have only two things to add: a note on quasisyntax, and an opinion
on implementation.
Matthew
Quasisyntax
-----------
When a `syntax' form is inside an unquote for `quasisyntax', the
`syntax' form is treated as part of the `quasisyntax'. The SRFI is not
entirely clear on what "inside" means, though.
For example, in
(quasisyntax ,(let-syntax ([m (lambda (stx)
(bound-identifier=? (syntax x)
(syntax x)))])
(m)))
the two uses of `syntax' are lexically in the `quasisyntax' form, but
since they're in a macro transformer, they are not part of the
`quasisyntax' for the purpose of identifier generativity. The expansion
result is #f.
In contrast, in
(quasisyntax ,(let-syntax ([m (lambda (stx)
(syntax
(bound-identifier=? (syntax x)
(syntax x))))])
(m)))
the two `syntax' forms are in the result of the expansion of `m', and
so they turn out to be part of the `quasisyntax', and the expansion
result is #t.
In summary, I think "inside" means "part of the macro expansion of an
unquoted expression".
This specification of "inside" has one surprising (to me) implication,
though. Given
(define-syntax m
(syntax-rules ()
[(_) (bound-identifier=? (syntax x) (syntax x))]))
then
(m)
expands to #f, but
(quasisyntax ,(m))
expands to #t.
I haven't been able to construct a realistic example where this
sensitivity to quasisyntax matters, and my guess is that it probably
doesn't. I'm still uncomfortable, though. If we refer to SRFI-72's
"improved hygiene" as "meta-hygiene", maybe this is just a problem with
"meta-meta-hygiene"? Does "meta-meta-hygiene" matter less than
"meta-hygiene"?
Implementation
--------------
I think the implementation of SRFI-42 and syntax-case (with phases) is
mostly the same. The only difference seems to be that syntax-case adds
a mark to identifiers introduced by a macro transformer, whereas
SRFI-72 adds a mark to identifiers introduced by a `syntax' form.
Shifting the mark to `syntax' means that marks do not have to cancel;
i.e., the macro expander doesn't have to add a mark to a transformer's
input and then add the same mark to the transformer's output, detecting
introduced identifiers as those that don't have the mark twice. Since
marks don't have to cancel, they're probably a little simpler to
implement, and maybe there's a different optimal choice of data
structures for representing lexical information.
More information about the R6RS
mailing list