I think you want this: (defn pairup [a b & rest] (cons [a b] (if rest (apply pairup rest) [])))
On Thu, Apr 29, 2010 at 3:32 PM, john.holland <[email protected]> wrote: > I'm pounding my head against the wall trying to understand how to do a > simple task. What I want to do is write a function that will take a > even-numbered set of numbers and split them into pairs. > > What I have right now is the following > > user> (defn pairup ([a b] [a b])([a b & rest] (cons (pairup a b) > (apply pairup rest))) ([] [] )) > #'user/pairup > user> (pairup 1 2 3 4 5 6 7 8) > ([1 2] [3 4] [5 6] 7 8) > user> > > > I can't get the last pair into a vector like the others. > > Can someone tell me what I am doing wrong? I know there is probably a > way using the language to do this but I ended up trying to do it from > scratch as a learning exercise. > > Thanks > > John > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to [email protected] > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > [email protected]<clojure%[email protected]> > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- Mark J. Reed <[email protected]> -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en
