(defn group [x]
(loop [newlist [] currlist x]
 (if (not (empty? x))
   (recur (newlist (cons (first x) newlist))
(newlist (cons (first x) newlist))  You are making a function call here
using an empty vector and your argument is a list. This is not possible,
that's why you have that error ([] (cons 7 [])). When you make a vector a
function its argument should the integer. Try and rework your code.
          (currlist (drop-while #(= (first currlist) %) currlist))
This won't work too. drop-while returns a lazy sequence so you have
(currlist (......))
          ))))

I would advice that you should spend some time with clojure, learning its
data structures, function call and others in order to full appreciate how
things play out .

Regards,
Emeka



On Mon, Nov 9, 2009 at 7:08 PM, Wilson MacGyver <wmacgy...@gmail.com> wrote:

>
> Thanks guys for the various solutions. I set out trying to try a recur
> solution
>
> So I came up with this. the idea is to go through the collection being
> passed, and grab one element, then do drop-while until a different
> element is encountered. repeat until there is no more left in the
> collection.
>
> (defn group [x]
> (loop [newlist [] currlist x]
>  (if (not (empty? x))
>    (recur (newlist (cons (first x) newlist))
>           (currlist (drop-while #(= (first currlist) %) currlist))
>           ))))
>
>
> It seems logical to me, but when I tried it with
> (group [1 1 2 2 3 3 ])
>
> I get
> CompilerException java.lang.IllegalArgumentException: Key must be integer
>
> what am I missing?
>
> Thanks
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to