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

Re: Macros in Dylan



On Tue, 2002-11-26 at 14:24, Paul Graham wrote:
> --Neel Krishnaswami wrote:
> 
> > I think that this is one of the great weaknesses of most current macro
> > languages: there's no good way to decompose a macro definition in the
> > way that regular programs can be.
> 
> I don't understand.  Macros are just functions that generate 
> lists, at least in the defmacro world.  Are you talking about 
> problems specific to some hygienic macro scheme?

No, hygiene isn't too much of a pain, IMHO--Chez Scheme SYNTAX-CASE
macros are fully hygienic, and they're approximately as difficult to use
as LISP macros.  (Granted, they force you to call SYNTAX-OBJECT->DATUM
when you need to "unwrap" something, and DATUM->SYNTAX-OBJECT when you
want violate hygiene.  On the other hand, you don't need to fool around
with GENSYM or worry about namespaces, so it works out pretty much
even.  And the tool support absolutely *rocks* compared to LISP macros. 
The DrScheme IDE continues to impress me.)

Neel's complaining about Scheme's SYNTAX-RULES, and the Dylan macro
system.  Both of these are based on pattern-matching rewrite rules, and
both make it (1) extremely easy to write small macros and (2) brutally
difficult to write big ones.  When all you've got is simple pattern
matching, complex transformations require pages of helper macros. 
Dylan's FOR loop, for example, requires about 5 pages of dense macrology
to support a tiny fraction of the features provided by LISP's LOOP
macro.

I think there are two major axes of variation in macro systems:

  1) Hygienic (Scheme) vs. non-hygienic (LISP).
  2) Pattern-based (SYNTAX-RULES) vs. programmatic (Lisp, SYNTAX-CASE).

I definitely prefer programmatic to pattern-based macros, because they
allow me to do funky stuff.  But I also like to have hygiene, for much
the same reason I like to have automatic storage management--it doesn't
cost me that much, and it prevents a whole class of bugs completely.

I've got a big SYNTAX-CASE macro which implements LISP-style keyword
arguments for DrScheme.  If you'd like a copy, just ask.

Cheers,
Eric