Jim
Jim

Reputation: 329

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?

Upvotes: 3

Views: 139

Answers (1)

Justin Kramer
Justin Kramer

Reputation: 4003

You want apply:

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

Upvotes: 8

Related Questions