Re: Simple sequence question: inserting something after blocks of fulfilling elements

2009-04-23 Thread Laurent PETIT
You version does not work for certain kind of data, (as did mine), see my answer to Meikel for more detail, -- Laurent 2009/4/23 Christophe Grand christo...@cgrand.net: Hi all! (defn mystery-function [pred coll]  (lazy-seq    (when (seq coll)      (let [[run etc] (split-with pred coll)]

Re: Simple sequence question: inserting something after blocks of fulfilling elements

2009-04-23 Thread Michael Wood
On Thu, Apr 23, 2009 at 9:44 AM, Laurent PETIT laurent.pe...@gmail.com wrote: Hi Meikel, It seems to me that your version is the only safe one so far, that would succesfully indefinitely return values with this test: (dorun (mystery-function true? :foo (repeat true))) Mine, a new version

Re: Simple sequence question: inserting something after blocks of fulfilling elements

2009-04-23 Thread Christophe Grand
*Warning this message contains mutable state and may hurt functional sensibilities.* Ugly hack: (defn my-split-with [pred coll] (let [s (atom coll) p #(when-let [r (pred %)] (swap! s rest) r)] [(take-while p coll) (drop-while pred (lazy-seq @s))])) Now it works ;-) Laurent

Re: Simple sequence question: inserting something after blocks of fulfilling elements

2009-04-23 Thread Laurent PETIT
1:2 user= (reduce #(concat %1 (if ( %2 6) [ :foo %2] [%2])) [] '(3 4 5 8 4 2)) (3 4 5 :foo 8 4 2) Not good, the expected result would have been (3 4 5 :foo 8 4 2 :foo) Regards, -- Laurent 2009/4/23 Emeka emekami...@gmail.com: (reduce #(concat %1 (if ( %2 6) [ :foo %2] [%2])) [] '(3 4 5 8 4

Re: Simple sequence question: inserting something after blocks of fulfilling elements

2009-04-23 Thread Emeka
Laurent, Sampi question was; Let's say I have a sequence of integers: (def a (3 9 1 5 102 -322 ...)) Is there a function for inserting an object—let's say :foo—after elements that fulfill a certain predicate? Furthermore, I mean inserting :foo after any block of elements that fulfill it:

Re: Simple sequence question: inserting something after blocks of fulfilling elements

2009-04-23 Thread Michael Wood
On Thu, Apr 23, 2009 at 2:11 PM, Emeka emekami...@gmail.com wrote: Laurent, Sampi question was; Let's say I have a sequence of integers:  (def a (3 9 1 5 102 -322 ...)) Is there a function for inserting an object—let's say :foo—after elements that fulfill a certain predicate?

Re: Simple sequence question: inserting something after blocks of fulfilling elements

2009-04-23 Thread Christophe Grand
Laurent PETIT a écrit : 2009/4/23 Christophe Grand christo...@cgrand.net: *Warning this message contains mutable state and may hurt functional sensibilities.* Ugly hack: (defn my-split-with [pred coll] (let [s (atom coll) p #(when-let [r (pred %)] (swap! s rest) r)]

Re: Simple sequence question: inserting something after blocks of fulfilling elements

2009-04-23 Thread Christophe Grand
Laurent PETIT a écrit : I guess you're right. But a little warning in the javadoc could help newcomers not shoot themselves in the foot. And the problem is, calling directly (second) without calling (first) would work most of the time. I wanted to make it fail every time = same behaviour

Re: Simple sequence question: inserting something after blocks of fulfilling elements

2009-04-23 Thread Laurent PETIT
2009/4/23 Christophe Grand christo...@cgrand.net: Laurent PETIT a écrit : I guess you're right. But a little warning in the javadoc could help newcomers not shoot themselves in the foot. And the problem is, calling directly (second) without calling (first) would work most of the time. I

Re: Simple sequence question: inserting something after blocks of fulfilling elements

2009-04-23 Thread Christophe Grand
Laurent PETIT a écrit : 2009/4/23 Christophe Grand christo...@cgrand.net: Laurent PETIT a écrit : I guess you're right. But a little warning in the javadoc could help newcomers not shoot themselves in the foot. And the problem is, calling directly (second) without calling (first)

Re: Simple sequence question: inserting something after blocks of fulfilling elements

2009-04-23 Thread Laurent PETIT
2009/4/23 Christophe Grand christo...@cgrand.net: Laurent PETIT a écrit : 2009/4/23 Christophe Grand christo...@cgrand.net: Laurent PETIT a écrit : I guess you're right. But a little warning in the javadoc could help newcomers not shoot themselves in the foot. And the problem is, calling

Simple sequence question: inserting something after blocks of fulfilling elements

2009-04-22 Thread samppi
Let's say I have a sequence of integers: (def a (3 9 1 5 102 -322 ...)) Is there a function for inserting an object—let's say :foo—after elements that fulfill a certain predicate? Furthermore, I mean inserting :foo after any block of elements that fulfill it: (mystery-function (partial 6)

Re: Simple sequence question: inserting something after blocks of fulfilling elements

2009-04-22 Thread Michael Wood
On Wed, Apr 22, 2009 at 4:57 PM, samppi rbysam...@gmail.com wrote: Let's say I have a sequence of integers:  (def a (3 9 1 5 102 -322 ...)) Is there a function for inserting an object—let's say :foo—after elements that fulfill a certain predicate? Furthermore, I mean inserting :foo after

Re: Simple sequence question: inserting something after blocks of fulfilling elements

2009-04-22 Thread Adam Blinkinsop
On Wed, Apr 22, 2009 at 9:58 AM, Michael Wood esiot...@gmail.com wrote: On Wed, Apr 22, 2009 at 4:57 PM, samppi rbysam...@gmail.com wrote: Let's say I have a sequence of integers: (def a (3 9 1 5 102 -322 ...)) Is there a function for inserting an object—let's say :foo—after

Re: Simple sequence question: inserting something after blocks of fulfilling elements

2009-04-22 Thread Laurent PETIT
2009/4/22 Michael Wood esiot...@gmail.com: On Wed, Apr 22, 2009 at 4:57 PM, samppi rbysam...@gmail.com wrote: Let's say I have a sequence of integers:  (def a (3 9 1 5 102 -322 ...)) Is there a function for inserting an object—let's say :foo—after elements that fulfill a certain

Re: Simple sequence question: inserting something after blocks of fulfilling elements

2009-04-22 Thread Meikel Brandmeyer
Hi, Am 22.04.2009 um 16:57 schrieb samppi: Let's say I have a sequence of integers: (def a (3 9 1 5 102 -322 ...)) Is there a function for inserting an object—let's say :foo—after elements that fulfill a certain predicate? Furthermore, I mean inserting :foo after any block of elements that

Re: Simple sequence question: inserting something after blocks of fulfilling elements

2009-04-22 Thread Michael Wood
On Wed, Apr 22, 2009 at 8:03 PM, Meikel Brandmeyer m...@kotka.de wrote: Hi, Am 22.04.2009 um 16:57 schrieb samppi: Let's say I have a sequence of integers: (def a (3 9 1 5 102 -322 ...)) Is there a function for inserting an object—let's say :foo—after elements that fulfill a certain

Re: Simple sequence question: inserting something after blocks of fulfilling elements

2009-04-22 Thread Meikel Brandmeyer
Hi Micheal, Am 22.04.2009 um 21:18 schrieb Michael Wood: Your version gives the same answer as mine, but I believe what he wants is something that skips over all the elements that pass the test and only inserts one instance of o after them. That's why in his example there is not a :foo after

Re: Simple sequence question: inserting something after blocks of fulfilling elements

2009-04-22 Thread Christophe Grand
Hi all! (defn mystery-function [pred coll] (lazy-seq (when (seq coll) (let [[run etc] (split-with pred coll)] (if (seq run) (concat run (cons :foo (mystery-function pred etc))) (cons (first coll) (mystery-function pred (rest coll Christophe