将列表散布到父项sexp中 [英] Spread a list into parent sexp
本文介绍了将列表散布到父项sexp中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在任何Lisp中是否存在可以传播"父sexp中的列表的表单?喜欢:
Is there a form in any lisp that could "spread" a list in the parent sexp? Like:
(+ (spread '(1 2 3))) -> (+ 1 2 3)
推荐答案
有两种方法.哪个更好取决于最终想要的东西.
There are two way to do it. Which is better depends on what you want in the end.
通常,您可以在`
(反引号)内使用,@
.计算,@
之后的形式以生成列表,然后将其拼接到模板中:
Generally, you can use ,@
inside `
(backquote). The form following ,@
is evaluated to produce a list, which is then spliced into the template:
* `(+ ,@'(1 2 3))
(+ 1 2 3)
* (eval `(+ ,@'(1 2 3)))
6
或者,如果您只想使用包装在列表中的参数来调用函数,则使用apply
函数将更加方便:
Or, if you just want to call a function with its arguments which are packed in a list, it will be more convenient to use the apply
function:
* (apply #'+ '(1 2 3))
6
这篇关于将列表散布到父项sexp中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文