Macros[by implementor of toy compiler]
Tue, 8 May 2001 03:15:06 -0400 (EDT)
Date: Mon, 7 May 2001 17:48:47 +0200 (CEST)
From: Michal Gajda <email@example.com>
* Introduction of general hygienic macro's as you propose, forces us to
cope with following problems:
1. Full typechecking of macros(in place of definition) seems to need
second-rank polymorphism. (Decidable, but harder to implement) Of course
you can delay typechecking until you expand all macros, but then
error-messages become unreadable.
An interesting option is to allow the macro writer to supply his own
type-checker that is then run before macro-expansion. Type errors can then
be presented to the user using the pre-expansion source code.
I can hear you all boggling over the lack of safety in what I have just
proposed. Suppose the macro-writer provides a bogus type-checker? Ack!
Unsafe code! Mid-air collisions! Nuclear melt-downs! Am I nuts!?
Actually no. Just do a separate type-check of the fully expanded code
using only the built-in type-checkers. If this verification check comes up
with a different answer, then one of your macros has a buggy type-checker.
(What you do about finding -that- bug and reporting it to the author of the
macro is another issue...)
A student did a Masters thesis for Olin Shivers and me at MIT last year
trying to work out the kinks in a macro facility that would work
approximately this way. The results were interesting, but not yet ready
for prime time.