公共Lisp——列表解包?(类似于Python)
在Python中,假设定义了以下函数:公共Lisp——列表解包?(类似于Python),python,list,lisp,common-lisp,iterable-unpacking,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个元素的列表,我可以
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))
有更好的方法吗?使用该功能:
(defun function (a b c)
... do stuff with a, b, c ...
(应用函数参数)
例如:
CL-USER>(应用#’(lambda(abc)(+abc))(1 2 3))
6.
请注意,这仅在列表中包含函数的唯一参数时有效。否则,需要使用解构绑定
,并与python执行函数(*args,另一个_arg)
的能力相匹配。请注意,还有类似的,@
。例如,(let((x'(23))`(1,@x45))
变为(12345)
。