在clojure中,如何将列表传递给参数化函数(& more)

时间:2011-12-14 22:41:23

标签: rest clojure parameterized

说我有功能:

(defn foo [something & otherthings]
  (println something)
  (println otherthings))

评估

(foo "ack" "moo" "boo")

给了我:

ack                                                               
(moo boo) 

如果我想用列表调用foo怎么办?

(foo "ack" (list "moo" "boo"))

并获取

ack                                                            
(moo boo) 

而不是

ack                                            
((moo boo)) 

有没有办法在不改变foo的情况下做到这一点?

1 个答案:

答案 0 :(得分:8)

您想要apply

(apply foo "ack" (list "moo" "boo"))