User Tools

A PCRE internal error occured. This might be caused by a faulty plugin

====== Function APPLY ====== ====Syntax==== * **apply** //function ''&rest'' args''+''// → //result''*''// ====Arguments and Values==== * //function// - a //[[CL:Glossary:function designator]]//. * //args// - a //[[CL:Glossary:spreadable argument list designator]]//. * //results// - the //[[CL:Glossary:value|values]]// returned by //function//. ====Description==== //[[CL:Glossary:apply|Applies]]// the //function// to the //args//. When the //function// receives its arguments via ''&rest'', it is permissible (but not required) for the //[[CL:Glossary:implementation]]// to //[[CL:Glossary:bind]]// the //[[CL:Glossary:rest parameter]]// to an //[[CL:Glossary:object]]// that shares structure with the last argument to **apply**. Because a //[[CL:Glossary:function]]// can neither detect whether it was called via **apply** nor whether (if so) the last argument to **apply** was a //[[CL:Glossary:constant]]//, //[[CL:Glossary:conforming program|conforming programs]]// must neither rely on the //[[CL:Glossary:list]]// structure of a //[[CL:Glossary:rest list]]// to be freshly consed, nor modify that //[[CL:Glossary:list]]// structure. **[[CL:Macros:setf]]** can be used with **apply** in certain circumstances; see section {\secref\SETFofAPPLY}. ====Examples==== <blockquote> ([[CL:Macros:defparameter]] *f* '[[CL:Functions:math-add|+]]) <r>[[CL:Functions:math-add|+]]</r> (apply *f* '(1 2)) <r>3</r> ([[CL:Macros:setf]] *f* #'[[CL:Functions:math-subtract|-]]) <r>[[CL:Functions:math-subtract|#<FUNCTION ->]] </r> (apply *f* '(1 2)) <r>-1 </r> (apply #'[[CL:Functions:max]] 3 5 '(2 7 3)) <r>7 </r> (apply '[[CL:Functions:cons]] '(([[CL:Functions:math-add|+]] 2 3) 4)) <r>(([[CL:Functions:math-add|+]] 2 3) . 4) </r> (apply #'[[CL:Functions:math-add|+]] '()) <r>0</r> ([[CL:Macros:defparameter]] *some-list* '(a b c)) <r>*SOME-LIST*</r> ([[CL:Macros:defun]] strange-test (&rest x) ([[CL:Functions:eq]] x *some-list*)) <r>STRANGE-TEST</r> (apply #'strange-test *some-list*) <r>//[[CL:Glossary:implementation-dependent]]//</r> ([[CL:Macros:defun]] bad-boy (&rest x) ([[CL:Functions:rplacd]] x 'y)) <r>BAD-BOY</r> (bad-boy 'a 'b 'c) <u>The above has undefined consequences.</u> (apply #'bad-boy *some-list*) <u>The above has undefined consequences.</u> ([[CL:Macros:defun]] foo (size &rest keys &key double &allow-other-keys) ([[CL:Special Operators:let]] ((v (apply #'[[CL:Functions:make-array]] size :allow-other-keys t keys))) ([[CL:Special Operators:if]] double ([[CL:Functions:concatenate]] ([[CL:Functions:type-of]] v) v v) v))) <r>FOO</r> (foo 4 :initial-contents '(a b c d) :double t) <r>#(A B C D A B C D)</r> </blockquote> ====Affected By==== None. ====Exceptional Situations==== None. ====See Also==== * **[[CL:Functions:funcall|Function FUNCALL]]** * **[[CL:Functions:fdefinition|Function FDEFINITION]]** * **[[CL:Special Operators:function|Special Operator FUNCTION]]** * {\secref\Evaluation} * {\secref\SETFofAPPLY} ====Notes==== None. \issue{FUNCTION-TYPE:X3J13-MARCH-88} \issue{REST-LIST-ALLOCATION:MAY-SHARE} \issue{REST-LIST-ALLOCATION:MAY-SHARE}