You can have this, but it's not beautiful:
(defun xx (&rest args)
(apply (lambda (&optional a)
(format t "xx: a: ~a~%" a)
(apply #'zz args)
)
args
) )
An alternative would be to introduce a special value denoting the default
value, say :default or :unspecific or so:
(defun zz (&optional (a ':default))
(when (eq a ':default) (setq a t))
...
)
Bruno
You can make use of the supplied-p argument that can be used with optional
arguments:
(defun xx (&optional (a nil a-supplied-p))
(format t "~&xx: a: ~A~%" a)
(if a-supplied-p
(zz a)
(zz)))
--
Barry Margolin, bar...@bbnplanet.com
GTE Internetworking, Powered by BBN, Cambridge, MA
Support the anti-spam movement; see <http://www.cauce.org/>
Please don't send technical questions directly to me, post them to newsgroups.
> (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.
(defun xx (&optional (a nil a-supplied?))
(format t "xx: a: ~a~%" a)
(if a-supplied?
(zz a)
(zz)))
(xx)
xx: a: NIL
zz: a: T
(xx nil)
xx: a: NIL
zz: a: NIL
--
--------------------------------------------------------------------------
Bernhard Pfahringer
Austrian Research Institute for http://www.ai.univie.ac.at/~bernhard/
Artificial Intelligence bern...@ai.univie.ac.at
this looks like a case for
(defun xx (&rest args &key ...)
(apply #'zz args))
if you don't need access to the actual arguments, you don't even need to
specify keyword arguments in xx. keywords arguments aren't processed at
all if there is no &key in the lambda list.
#\Erik
--
if you think this year is "97", _you_ are not "year 2000 compliant".
see http://www.naggum.no/emacs/ for Emacs-20-related material.