[plt-scheme] defmacro (define-macro) and hygienic macros

From: Noel Welsh (noelwelsh at yahoo.com)
Date: Wed Mar 12 06:13:50 EST 2003

--- Rohan Nicholls <rohan.nicholls at informaat.nl>
> When I look at the documentation for defmacro, I see
> that a
> datum->syntax-object and back again is used, but I
> was under the
> impression that unhygienic macros were just that

Ok, a bit of history should explain what's going on
here.  In old Lisp implementations the internal
representation of code is s-expressions.  So the
external representation  e.g.

  (lambda (x) (+ x 1))

was exactly the internal representation the
compiler/interpreter operated on.  Hence it was
natural that non-hygenic macros should emit

This doesn't work too well for more advanced systems. 
Basically there is nowhere to store additional
information (such as the inferred types of expressions
for a compiler, or environment information for a
hygenic macro system).  You'd have to use some
convention to denote annotations to the source code
and then you're back in Emacs Lisp "if the cadr is the
symbol foo the rest of the list is interpreted as..."
hell.  So PLT Scheme uses a richer internal
representation of syntax - the syntax object.  This in
turn means that defmacro style macros can no longer
return just s-expressions - they must return
syntax-objects.  Hence the conversion in defmacro. 
This has nothing to do with hygiene as hygenic macros
also return syntax-objects.  The difference is they
also make use of the additional information stored in
a syntax-object, which defmacro doesn't.

HTH.  If I've got anything wrong I'm sure others will
correct me.


Do you Yahoo!?
Yahoo! Web Hosting - establish your business online

Posted on the users mailing list.