[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Fixing optional arguments?
- To: Common-Lisp@SU-AI.arpa
- Subject: Fixing optional arguments?
- From: Gregor Kiczales <Gregor.pa@Xerox.COM>
- Date: Wed, 27 Aug 1986 13:24:00 -0000
- Cc: Gregor.pa@Xerox.COM
- Sender: Gregor.pa@Xerox.COM
A standard problem with optional arguments in Common Lisp is that it
difficult to use the fact that a function was only called with n
arguments to call some other function with only n arguments. For
(defun foo (x &optional (y nil y-p))
(bar x y)
This is a proposed solution to that problem.
- The default default value for an optional argument is the value of the
constant UNSUPPLIED-OPTIONAL-ARGUMENT (instead of nil).
So given the definition (defun foo (x &optional y) y). (foo 1) would
return the value of the constant unsupplied-optional-argument.
- When function call sees the value of unsupplied-optional-argument
being used as an argument to a function, it treats it as an unsupplied
value for an optional argument. As an important performance
optimization, any arguments following unsupplied-optional-argument are
The example becomes:
(defun foo (x &optional y)
(bar x y) ..)
In addition, it is possible to write code like:
;; We are only going to call baz with 2 arguments.
(setq arg-3 unsupplied-optional-argument))
(baz arg-1 arg-2 arg-3 arg-4)
In this example, the call to baz will be as if only two arguments were
The supplied-p variable stuff is also no longer needed since the same
thing can be determined by using (unsupplied-optional-argument-p <arg>).