如何使用列表作为参数 [英] How to use list as parameters
本文介绍了如何使用列表作为参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Clojure的新人,所以这个问题可能很小:
I am new to Clojure so this question may be trivial:
假设你有一个列表(\h \e \ l \l \o)
,并且您希望在调用函数时将其用作实际参数,例如 str
得到相同的结果:
Suppose you have a list (\h \e \l \l \o)
and you want to use it as the actual parameters when calling a function, for example, str
in order to get the same result as:
(str \h \e \l \l \o)
我使用eval得到一个解决方案:
I came to a solution using eval:
(def paramlist '(\h \e \l \l \o))
(eval (conj paramlist str))
但我知道这是相当肮脏,过度杀死的问题。这是最好的解决方案是什么?
But I understand that is quite dirty and over killing the problem. What is the best solution to do this?
推荐答案
使用 apply
user=> (apply str '(1 2 3 4))
"1234"
这篇关于如何使用列表作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文