如何“扩展”列表作为函数的参数?

时间:2014-11-30 05:45:15

标签: clojure arguments

如何让这三个片段有效?

(defn bar [a b c] (println a b c))
> (bar :a :b :c)
:a :b :c

(defn foo [a & args] (bar a args)) ;; some magic is needed here.
> (foo :a :b :c)
MoralException: You're a bad person for trying this.

我已经全神贯注地看到了如何做到这一点。我尝试过很多像(apply bar [a args])这样的东西,但这是一个ArityException(这很有意义)。我该怎么办?

1 个答案:

答案 0 :(得分:2)

您不需要在向量中将参数包装到apply

(apply bar a args)

干预参数前置于args