Search code examples
restclojureparameterized

In clojure, how do you pass a list to a parameterized function (&more)


Say I have function:

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

evaluating

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

gives me :

ack                                                               
(moo boo) 

what if I want to call foo with a list?

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

and get

ack                                                            
(moo boo) 

instead of

ack                                            
((moo boo)) 

Is there any way to do that without changing foo?


Solution

  • You want apply:

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