&rest
args+
→ result*
Applies the function to the args.
When the function receives its arguments via &rest
, it is permissible (but not required) for the implementation to bind the rest parameter to an object that shares structure with the last argument to apply. Because a function can neither detect whether it was called via apply nor whether (if so) the last argument to apply was a constant, conforming programs must neither rely on the list structure of a rest list to be freshly consed, nor modify that list structure.
setf can be used with apply in certain circumstances; see section {\secref\SETFofAPPLY}.
(defparameter *f* '+)
→(apply *f* '(1 2))
→3
→(apply *f* '(1 2))
→-1
(apply #'max 3 5 '(2 7 3))
→7
→((+ 2 3) . 4)
(apply #'+ '())
→0
(defparameter *some-list* '(a b c))
→*SOME-LIST*
(defun strange-test (&rest x) (eq x *some-list*))
→STRANGE-TEST
(apply #'strange-test *some-list*)
→(defun bad-boy (&rest x) (rplacd x 'y))
→BAD-BOY
(bad-boy 'a 'b 'c)
?The above has undefined consequences.
(apply #'bad-boy *some-list*)
?The above has undefined consequences.
(defun foo (size &rest keys &key double &allow-other-keys) (let ((v (apply #'make-array size :allow-other-keys t keys))) (if double (concatenate (type-of v) v v) v)))
→FOO
(foo 4 :initial-contents '(a b c d) :double t)
→#(A B C D A B C D)
None.
None.
None.
\issue{FUNCTION-TYPE:X3J13-MARCH-88} \issue{REST-LIST-ALLOCATION:MAY-SHARE} \issue{REST-LIST-ALLOCATION:MAY-SHARE}