Ah that was what I was missing. You are right,
I misunderstood the recur form.
For some reason I thought in recur you have to specify the
name of the variable that it's bound to.
so when I wrote
(recur (newlist (cons (first x) newlist))
I thought I was saying in recur, rebind (cons (first x) ne
Hi,
Am 09.11.2009 um 20:08 schrieb Wilson MacGyver:
> (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
On Mon, Nov 9, 2009 at 2:31 PM, Emeka wrote:
>
> (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. Th
(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
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.
On Mon, Nov 09, 2009 at 04:49:16PM +, Emeka wrote:
>What is the gain of using lazy-seq here? Why can't we go without laziness?
- The lazy version doesn't consume stack per length of the sequence.
- The lazy version works with unbounded sequences.
For short sequences it probably doesn'
Meikel,
What is the gain of using lazy-seq here? Why can't we go without laziness?
(defn group
[s]
(when-let [s (seq s)]
(let [f(first s)
[fs & r] (split-with #(= % f) s)]
(cons fs (group r)
Regards,
Emeka
On Mon, Nov 9, 2009 at 4:44 PM, Emeka wrot
Meikel,
Is like you over engineered your version?
(defn group
[s]
(lazy-seq
(when-let [s (seq s)]
(let [f(first s)
[fs & r] (split-with #(= % f) s)]
(cons fs (group r))
Should be ..
(defn group
[s]
(lazy-seq
(when-let [s (seq s)]
(let [f
Hi,
Am 09.11.2009 um 07:33 schrieb Wilson MacGyver:
> I did search in the API docs for both core and contrib, but didn't
> find anything like
> it.
>
> Does Clojure have a function like Haskell's group?
>
> In Haskell,
> Input: group [1,2,2,1,1,1,2,2,2,1]
> Output: [[1],[2,2],[1,1,1],[2,2,2],[1]]
ah, thank you for the help!
On Mon, Nov 9, 2009 at 1:57 AM, Alex Osborne wrote:
>
> Wilson MacGyver wrote:
>> Does Clojure have a function like Haskell's group?
>>
>> In Haskell,
>> Input: group [1,2,2,1,1,1,2,2,2,1]
>> Output: [[1],[2,2],[1,1,1],[2,2,2],[1]]
>
> (use 'clojure.contrib.seq-utils)
Wilson MacGyver wrote:
> Does Clojure have a function like Haskell's group?
>
> In Haskell,
> Input: group [1,2,2,1,1,1,2,2,2,1]
> Output: [[1],[2,2],[1,1,1],[2,2,2],[1]]
(use 'clojure.contrib.seq-utils)
(partition-by identity [1 2 2 1 1 1 2 2 2 1])
=> ((1) (2 2) (1 1 1) (2 2 2) (1))
--~--~---
Hi,
I did search in the API docs for both core and contrib, but didn't
find anything like
it.
Does Clojure have a function like Haskell's group?
In Haskell,
Input: group [1,2,2,1,1,1,2,2,2,1]
Output: [[1],[2,2],[1,1,1],[2,2,2],[1]]
Thanks
--
Omnem crede diem tibi diluxisse supremum.
--~--~-
12 matches
Mail list logo