On Sun, Aug 30, 2009 at 8:09 AM, Emeka<emekami...@gmail.com> wrote: > Hello All, > > I was fooling around with clojure and I found something I have not noticed > before. Could someone explain it ? > > (defn foo [ &v] > (apply + &v)) > > Is '&' + the identifier's name another where of making sure that the > parameterĀ must beĀ a collection? > Or is there something I am doing wrong here? To be honest, I am pretty > tired.
It looks like if the & is right next to the v then it is treated as single parameter name rather than saying that v is a parameter that collects all the remaining arguments (all of them in this case). With that code, the argument needs to be a collection. You can do this: (foo '(1 2 3)) -> 6 However, it would be better to do this: (defn foo [& v] (apply + v)) (foo 1 2 3) -> 6 -- R. Mark Volkmann Object Computing, Inc. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---