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


There are 2 possible uses of macros:

- To provide SYNTACTIC EXTENSIONS to the language for convenience and
clarity.  This is the only legitimate use (as far as I'm concerned) of
a macro facility.  Examples of this are COND (in terms of IF) and LET
(in terms of LAMBDA).  Note that macros are needed for this case not
because of order of evaluation (the main difference, besides
assignment, between lambda calculus and Scheme), but rather because
the forms do not make sense as procedure applications.  For example,

(let ((y (+ 2 3))) (* y y))

in a position where y is not bound.  If LET were a procedure, it would
receive 2 arguments ((y (+ 2 3))) and (* y y).  But then y would be a
free variable in the above expression, irrelevant of the order of
evaluation, which is certainly not the desired effect.  To obtain the
desired effect, something like a macro would be needed even in a
system which more closely modelled the lambda calculus.  Thus there is
something to macros which normal order evaluation in the lambda
calculus does not provide.

When used this way they are mere re-write rules (even character level)
and evaluation plays no part in them.  The re-write can be seen as
happening before the program is evaluated, since these expressions
would have no reasonable meaning otherwise.  Back-quote and comma can
be seen as ways of specifying string substitution.

- To obtain the effects of normal order evaluation, locatives, or
fexprs in a simple applicative order system like Scheme.  Consider,
for example, the standard Lisp SETF macro (not the T version which
falls into the previous category).  This is however a MISUSE, as far
as I am concerned, and the desired effect should be obtained
otherwise.  I believe it is in this case that all of the problems
about order of evaluation, etc. arise, which is not too surprising,
since a tool is being used for something other than its real purpose.

Just because a tool can be abused, it does not mean that it is wrong
or that it is inherently broken if it does not work when it is used
for a purpose other than its intended one.