繁体   English   中英

Common Lisp - 列出拆包? (类似于Python)

[英]Common Lisp — List unpacking? (similar to Python)

在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   

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM