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

&optional args in DEFMACRO

Consider the following bit of code:

(defmacro foo (a &optional (b 'b-default))
  `(list ,a ,b))

(macroexpand (foo 'bar))

Which of the following is returned by the MACROEXPAND:

X.  (list 'bar b-default)
Y.  (list 'bar 'b-default)

In other words, is the default argument evaluated at macro-expansion
time or is it quoted -- bound to its variable verbatim.  The manual is
silent on this, I think.  To me, answer Y (quoted default) seems
intuitively right: since A is bound to a verbatim chunk of the calling
form, and B would be too if the calling form were long enough, it seems
right to bind B to the default form without evaluation.  However, the
tradition from Maclisp seems to be that the default is evaluated,
producing answer X.  It seems that if you want an expansion like Y, you
have to write the defmacro arglist as (a &optional (b ''b-default)).  At
least, that's what Maclisp just did when I tried this -- I'm not sure
how old or how ingrained this decision is.

Opinions?  I guess that post-freeze conservatism would dictate that we
should stick with the Maclisp definition, unless this is viewed as
obviously wrong.  In any event, the manual needs to be tightened here,
if it's not too late.

-- Scott