在 Python 中,假设定义了以下函数:
def function(a, b, c):
... do stuff with a, b, c ...
我可以通过 Python 的序列解包来使用该函数:
arguments = (1, 2, 3)
function(*arguments)
Common Lisp 中是否存在类似的功能?所以如果我有一个函数:
(defun function (a b c)
... do stuff with a, b, c ...
如果我有一个包含 3 个元素的列表,我可以轻松地将这 3 个元素用作函数的参数吗?
我目前的实现方式是这样的:
(destructuring-bind (a b c) (1 2 3)
(function a b c))
有没有更好的办法?
最佳答案
使用 apply
功能:
(apply #'function arguments)
例子:
CL-USER> (apply #'(lambda (a b c) (+ a b c)) '(1 2 3))
6
关于python - Common Lisp——列表拆包? (类似于 Python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4451854/