Thanks Timothy. That did the trick. One small comment below. On Feb 19, 12:11 am, Timothy Pratley <timothyprat...@gmail.com> wrote: > On 19 February 2010 18:04, Julien <julien.c.chast...@gmail.com> wrote: > > > > > Question #1 > > > I want to write a vararg function that does something like this: > > > (map vector [1 2 3] [4 5 6]) > > which yields > > ([1 4] [2 5] [3 6]) > > > I try to capture this as a function: > > > (defn rotate[& x] (map vector x)) > > > but > > > (rotate [1 2 3] [4 5 6]) > > > yields > > > ([[1 2 3]] [[4 5 6]]) instead of ([1 4] [2 5] [3 6]) > > > What am I doing wrong? > > You want apply... > > clojure.core/apply > ([f args* argseq]) > Applies fn f to the argument list formed by prepending args to argseq. > > foo=> (defn rotate [& x] (apply map vector x)) > #'foo/rotate > foo=> (rotate [1 2 3] [4 5 6]) > ([1 4] [2 5] [3 6]) > > > > > Question #2 > > > Question #1 was somewhat of a diversion. What I actually want my > > function to look like is something like this: > > > (defn rotate[x] (map vector x)) > > > where the x passed in is a vector of vectors e.g. [[4 2 3] [ 9 8 7]] > > > so > > > (rotate [[1 2 3] [4 5 6]]) > > > would yield > > > ([1 4] [2 5] [3 6]) > > > How can I achieve this? > > same answer :)
Almost the same answer: (defn rotate [x] (apply map vector x)) -- 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