How to use list as parameters

微笑、不失礼 提交于 2019-12-13 05:18:38

问题


I am new to Clojure so this question may be trivial:

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) 

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?


回答1:


Use apply

user=> (apply str '(1 2 3 4))
"1234"


来源:https://stackoverflow.com/questions/25621696/how-to-use-list-as-parameters

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!