gpt4 book ai didi

common-lisp - 什么时候使用 “apply”?什么时候使用 “funcall”?

转载 作者:行者123 更新时间:2023-12-03 14:38:19 38 4
gpt4 key购买 nike

Common Lisp HyperSpec在funcall条目中说,

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

由于它们在某种程度上是等效的,因此您什么时候使用 apply以及何时使用 funcall

最佳答案

如果您有一个或多个单独的参数,则应使用funcall;如果您的参数在列表中,则应使用apply

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

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

关于common-lisp - 什么时候使用 “apply”?什么时候使用 “funcall”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3862394/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com