When do you use “apply” and when “funcall”?

前端 未结 3 1163
遥遥无期
遥遥无期 2021-02-04 02:33

The Common Lisp HyperSpec says in the funcall entry that

(funcall function arg1 arg2 ...) 
==  (apply function arg1 arg2 ... nil) 
==  (app         


        
3条回答
  •  天涯浪人
    2021-02-04 03:10

    You should use funcall if you have one or more separate arguments and apply if you have your arguments in a list

    (defun passargs (&rest args) (apply #'myfun args))
    

    or

    (defun passargs (a b) (funcall #'myfun a b))
    

提交回复
热议问题