2013/3/26 Ryan <arekand...@gmail.com>

> Thanks Michael, but If i am not mistaken, your example only works with a
> vector with two elements. What if we have an unknown number of vector
> elements?
> My apologies if that wasn't clear on my first post.
>

If your function's signature allows for & rest arguments, it will work. If
not, you will get a wrong arity exception:

user=> (apply (fn [a b] (println a b)) [:a :b :c :d :e])
ArityException Wrong number of args (5) passed to: user$eval353$fn
 clojure.lang.AFn.throwArity (AFn.java:437)

user=> (apply (fn [a b & xs] (println a b)) [:a :b :c :d :e])
:a :b
nil

-- 
MK

http://github.com/michaelklishin
http://twitter.com/michaelklishin

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to