tags:

views:

63

answers:

1

Is there a way to expand a vector of values into the arguments of a function? e.g. something like this:

(defn addnums [a b]
  (apply + (flatten [a b])))

(def args [[1 2 3] [1 2 3]])

(addnums *args)
+6  A: 

You can just use apply again:

(apply addnums args)
sepp2k
Ah, `apply` definitely makes sense now! For some reason it didn't click that `(apply + [1 2 3]) == (+ 1 2 3)`. Thanks!
Ashley Williams