[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: define-macro in v200
Quoting Lauri Alanko:
> To get acquainted with the new syntax system, I tried to implement
> define-macro. This is what I came up with:
>
> (define-syntax (define-macro stx)
> (syntax-case stx ()
> ((_ (macro . args) . body)
> (syntax (define-macro macro (lambda args . body))))
> ((_ macro transformer)
> (syntax
> (define-syntax (macro stx2)
> (let ((v (syntax-object->datum stx2)))
> (datum->syntax-object
> stx2
> (apply transformer (cdr v)))))))))
>
> Does this look sensible?
Yes. In fact, it's better than the one embedded in the MzScheme release
notes, which uses `(quote-syntax here)' as the first argument to
`datum->syntax-object'.
Somehow I had convinced myself that `define-macro' would interact too
badly with hygienic macros to be useful, and that's why there was no
compatibility form. But it works ok.
A fancier `define-macro' could even track the S-expressions that go
into a macro and return unmodified. It could then restore the original
syntax objects, which might have source information. In fact, that's
what Zodiac does. (Zodiac is DrScheme 103's syntax system.)
I'm inclined to put `define-macro' into a new "defmacro.ss" library,
though, instead of building it into MzScheme. Does that seem like a
reasonable compromise?
Matthew