Re: every-nth

2010-11-25 Thread Sunil S Nandihalli
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 n coll))) Since you want to learn how lazy-seq works here some feedback. * Make

Re: every-nth

2010-11-25 Thread Meikel Brandmeyer
Hi, On 25 Nov., 09:40, Sunil S Nandihalli sunil.nandiha...@gmail.com 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

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

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 (first s) (evn n (next s                 (evn (dec

Re: every-nth

2010-11-24 Thread Ken Wesson
On Wed, Nov 24, 2010 at 11:11 PM, Baishampayan Ghose b.gh...@gmail.com 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 s               (if (= cn 1

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 b.gh...@gmail.com 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

Re: every-nth

2010-11-24 Thread Ken Wesson
On Wed, Nov 24, 2010 at 11:53 PM, David Sletten da...@bosatsu.net wrote: On Nov 24, 2010, at 11:45 PM, Ken Wesson wrote: On Wed, Nov 24, 2010 at 11:11 PM, Baishampayan Ghose b.gh...@gmail.com wrote:  I just needed a function for every-nth element in a sequence.. I know it can be trivially

Re: every-nth

2010-11-24 Thread David Sletten
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 (evn (dec cn) (next s)] (evn n coll

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

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 kwess...@gmail.com wrote: Eh. This is weird. It seems that (partition n

Re: every-nth

2010-11-24 Thread Stuart Campbell
On 25 November 2010 16:56, Ken Wesson kwess...@gmail.com 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

Re: every-nth

2010-11-24 Thread Meikel Brandmeyer
Hi, On 25 Nov., 05:06, Sunil S Nandihalli sunil.nandiha...@gmail.com 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 n