python - Common Lisp——列表拆包? (类似于 Python)

标签 python list lisp common-lisp iterable-unpacking

在 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/

相关文章:

random - 由 sbcl 编译的执行文件不能使随机或使打开文件工作

python - Django:为什么 'Class' 对象不可迭代

python - 在 MacOS 上安装 Spyder/Python - 非常令人沮丧

python for 循环

python - 反转列表元组的顺序

Lisp - 返回函数的函数

lisp - 对排序的整数列表进行分组的惯用方法?

python - 使用不同的线程读取文件

Python 排序 - 对象列表

python - 如何获得其权重受 Python 3.6 中的变量限制的列表的加权平均值