《通链参考手册》


Function APPLY

●语法设定:

apply function &rest args+ => result*

●参数和值:

function---a function designator.

args---a spreadable argument list designator.

results---the values returned by function.

●详情:

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 5.1.2.5 (APPLY Forms as Places).

●例子:

 (setq f '+) =>  +
 (apply f '(1 2)) =>  3
 (setq f #'-) =>  #<FUNCTION ->
 (apply f '(1 2)) =>  -1
 (apply #'max 3 5 '(2 7 3)) =>  7
 (apply 'cons '((+ 2 3) 4)) =>  ((+ 2 3) . 4)
 (apply #'+ '()) =>  0

 (defparameter *some-list* '(a b c))
 (defun strange-test (&rest x) (eq x *some-list*))
 (apply #'strange-test *some-list*) =>  implementation-dependent

 (defun bad-boy (&rest x) (rplacd x 'y))
 (bad-boy 'a 'b 'c) has undefined consequences.
 (apply #'bad-boy *some-list*) 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 4 :initial-contents '(a b c d) :double t)
    =>  #(A B C D A B C D)

●受制于: 无。

●例外情况: 无。

●更多信息:

funcall, fdefinition, function, Section 3.1 (Evaluation), Section 5.1.2.5 (APPLY Forms as Places)

●说明: 无。


X3J13设计清单非标准部分,可查下面章节:


◇首页 § ◎章节目录 § □内容索引 § ○符号索引 § △术语表 § ※设计草案