In article <·············@WINTERMUTE.eagle> SDS <···········@cctrading.com> writes:
> (defun zz (&optional (a t)) (format t "zz: a: ~a~%" a))
> (defun xx (&optional a) (format t "xx: a: ~a~%" a) (zz a))
> (xx)
> xx: a: nil
> zz: a: nil
> nil
>
> .... But I want zz to use the default argument! ...
(defun xx (&rest args) ;[1]
(format t "xx: a: ~a~%" (first args))
(apply #'zz args))
or
(defun xx (&optional (a nil a-p)) ;[2]
;; Note that variable a-p will be t if a is supplied
;; and nil otherwise; it's called a "supplied-p parameter".
(format t "xx: a: ~a~%" a)
(if a-p (zz a) (zz)))
or
(defun xx (&optional (a t)) ;[3]
(format t "xx: a: ~a~%" a)
(zz a))
NOTES:
If you like [1] but want a to be available, too, you can use:
(defun xx (&rest args) ;[1a]
(destructuring-bind (&optional a) args
(format t "xx: a: ~a~%" a)
(apply #'zz args)))
As for [3], the point is that one can just do the same arg defaulting
in multiple functions. It's sometimes tedious and easy to get out of
alignment if the default changes in one since you have to remember
to update the other functions. But it is possible, and in some
situations it's the preferred approach.