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

&optional args in DEFMACRO



    Date: Fri, 1 Jul 1983  03:47 EDT
    From: Scott E. Fahlman <Fahlman at CMU-CS-C>
    (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)

X, (assuming you meant (macroexpand '(foo 'bar))) because its is more
general to allow the user to compute something.  I personally would write:

(defmacro foo (a &optional (b `b-default)) ...)
and
(defmacro foo (a &optional (b `'b-default)) ...)

using backquote to emphasize that this is a form that will return a piece
of code as a value.  Note that a default is treated just like the body of a
defmacro in terms of when it is evaluated etc.  A default in a defun is
also treated identically to the body of a defun.