Re: every-nth

2010-11-25 Thread Meikel Brandmeyer
Hi, On 25 Nov., 09:40, Sunil S Nandihalli wrote: > Thanks Meikel for such an insightful feedback. Its hard to imagine so much > thought goes into writing trivial looking functions. There are several interpretations of the word "trivial." One is "easy" or "simple" (where one could dispute whethe

Re: every-nth

2010-11-25 Thread Sunil S Nandihalli
Thanks Meikel for such an insightfull feedback. Its hard to imagine so much thought goes into writing trivial looking functions. Sunil. On Thu, Nov 25, 2010 at 1:00 PM, Meikel Brandmeyer wrote: > Hi, > > On 25 Nov., 05:06, Sunil S Nandihalli > wrote: > > > (defn every-nth

Re: every-nth

2010-11-24 Thread Meikel Brandmeyer
Hi, On 25 Nov., 05:06, Sunil S Nandihalli wrote: > (defn every-nth [n coll] >   (letfn [(evn [cn s] >             (when s >               (if (= cn 1) >                 (lazy-seq (cons (first s) (evn n (next s >                 (evn (dec cn) (next s)] >     (evn

Re: every-nth

2010-11-24 Thread Stuart Campbell
On 25 November 2010 16:56, Ken Wesson wrote: > Eh. This is weird. It seems that (partition n coll) drops the last > part of coll if it's not a multiple of n in size; e.g. (partition 3 [1 > 2 3 4 5]) yields ((1 2 3)) and not ((1 2 3) (4 5)). (partition n n [] > coll) does do that though. > See al

Re: every-nth

2010-11-24 Thread Sunil S Nandihalli
Thanks everybody, Clojure community is awesome .. and also I just wanted to learn to use lazy-seq that is why it was written in the way I showed you all. Thanks again. Sunil. On Thu, Nov 25, 2010 at 11:26 AM, Ken Wesson wrote: > Eh. This is weird. It seems that (partition n coll) drops the las

Re: every-nth

2010-11-24 Thread Ken Wesson
Eh. This is weird. It seems that (partition n coll) drops the last part of coll if it's not a multiple of n in size; e.g. (partition 3 [1 2 3 4 5]) yields ((1 2 3)) and not ((1 2 3) (4 5)). (partition n n [] coll) does do that though. OTOH, (mapcat identity (partition 1 n coll)) (apply concat (pa

Re: every-nth

2010-11-24 Thread David Sletten
just needed a function for every-nth element in a sequence.. I know it >>>> can be trivially implemented as .. >>>> (defn every-nth [n coll] >>>> (letfn [(evn [cn s] >>>>(when s >>>> (if (= cn 1) >>>&

Re: every-nth

2010-11-24 Thread Ken Wesson
On Wed, Nov 24, 2010 at 11:53 PM, David Sletten wrote: > > On Nov 24, 2010, at 11:45 PM, Ken Wesson wrote: > >> On Wed, Nov 24, 2010 at 11:11 PM, Baishampayan Ghose >> wrote: >>>>  I just needed a function for every-nth element in a sequence.. I know it >

Re: every-nth

2010-11-24 Thread David Sletten
On Nov 24, 2010, at 11:45 PM, Ken Wesson wrote: > On Wed, Nov 24, 2010 at 11:11 PM, Baishampayan Ghose > wrote: >>> I just needed a function for every-nth element in a sequence.. I know it >>> can be trivially implemented as .. >>> (defn every-nth

Re: every-nth

2010-11-24 Thread Ken Wesson
On Wed, Nov 24, 2010 at 11:11 PM, Baishampayan Ghose wrote: >>  I just needed a function for every-nth element in a sequence.. I know it >> can be trivially implemented as .. >> (defn every-nth [n coll] >>   (letfn [(evn [cn s] >>             (when

Re: every-nth

2010-11-24 Thread Baishampayan Ghose
>  I just needed a function for every-nth element in a sequence.. I know it > can be trivially implemented as .. > (defn every-nth [n coll] >   (letfn [(evn [cn s] >             (when s >               (if (= cn 1) >                 (lazy-seq (cons (fi

every-nth

2010-11-24 Thread Sunil S Nandihalli
Hello everybody, I just needed a function for every-nth element in a sequence.. I know it can be trivially implemented as .. (defn every-nth [n coll] (letfn [(evn [cn s] (when s (if (= cn 1) (lazy-seq (cons (first s) (evn n (next s