Re: destructuring / rest (was: Re: Counting vowels, take II.)

2010-03-24 Thread Douglas Philips
On 2010 Mar 24, at 2:39 AM, Meikel Brandmeyer wrote: On Mar 24, 2:22 am, Douglas Philips wrote: would (let [s1 (first seq1) s1tail (rest seq1)] ...) be any better? rest says it calls seq on its argument, and that would force as well? Hmmm... So only things like map are able to real

Re: destructuring / rest (was: Re: Counting vowels, take II.)

2010-03-23 Thread Meikel Brandmeyer
Hi, On Mar 24, 2:22 am, Douglas Philips wrote: > would (let [s1 (first seq1) >              s1tail (rest seq1)] ...) > be any better? rest says it calls seq on its argument, and that would   > force as well? > Hmmm... So only things like map are able to realize first without   > realizing (first

Lazyness of range (was: Re: Counting vowels, take II.)

2010-03-23 Thread Douglas Philips
On 2010 Mar 23, at 9:28 PM, Per Vognsen wrote: So you can see that scan-filter-zip is lazy in the source sequence but apparently not the primary input sequence. That was surprising to me because I see nothing in my code that should have forced that. Then I remember that some functions like range

Re: Counting vowels, take II.

2010-03-23 Thread Per Vognsen
For laziness analysis, I typically use code like this: (defn trace-seq* [name xs] (for [x xs] (do (println (str name ": " x)) x))) (defmacro trace-seq [xs] `(trace-seq* ~(str xs) ~xs)) If I use it on the code I posted, I get this: user> (take 3 (scan-filter-zip even? (trace-seq

destructuring / rest (was: Re: Counting vowels, take II.)

2010-03-23 Thread Douglas Philips
On 2010 Mar 23, at 4:13 PM, Meikel Brandmeyer wrote: (let [[s1 & s1tail] seq1 In the above destructuring the first element of s1tail is also realised. That is what I mean with "one step ahead". I'm not sure why it is done like this. I does not seem necessary. But I'm not an expert in

Re: Counting vowels, take II.

2010-03-23 Thread Meikel Brandmeyer
Hi, On Tue, Mar 23, 2010 at 01:33:54PM -0400, Douglas Philips wrote: > >> (let [[s1 & s1tail] seq1 > > > >Don't use this destructuring in this case, because it forces again the > >realisation of the seq one step ahead. > > If I need s1 anyways, what is the "one step ahead part" that yo

Re: Counting vowels, take II.

2010-03-23 Thread Douglas Philips
On 2010 Mar 23, at 8:26 AM, Meikel Brandmeyer wrote: here some notes: Thanks! I would use vector instead of list in the example since vector is more idiomatic in Clojure. Ok. Just my old lisp roots showing. Still haven't gotten the fingers/ spine rewired to use [] around defn parameters.

Re: Counting vowels, take II.

2010-03-23 Thread Douglas Philips
On 2010 Mar 23, at 9:14 AM, Per Vognsen wrote: Remember the one-liner I gave you last time? Yup. It was the 'hard coded + 0' parts that had been ruminating in the back of my mind as being something that could be abstracted out. :) Since the one you just posted didn't have all the features

Re: Counting vowels, take II.

2010-03-23 Thread Per Vognsen
Remember the one-liner I gave you last time? (defn indexed-pred [pred coll] (map #(if (pred %1) [%2 %1] [%1]) coll (reductions + 0 (map #(if (pred %) 1 0) coll Here's how little it has to change: (defn funkymonkey [pred src coll] (map #(if (pred %1) [(first %2) %1] [%1]) coll (reductions

Re: Counting vowels, take II.

2010-03-23 Thread Meikel Brandmeyer
Hi, here some notes: On Mar 23, 12:53 pm, Douglas Philips wrote: >        (semi-map vowel? list \"Hellow Word\" (iterate inc 1)) >     -> (\\H (\\e 1) \\l \\l (\\o 2) \\w \\space \\W (\\o 3) \\r \\d)" I would use vector instead of list in the example since vector is more idiomatic in Clojure.

Counting vowels, take II.

2010-03-23 Thread Douglas Philips
Last week, Per Vognsen answered my first version of this question, how can I number just the vowels in a string: http://groups.google.com/group/clojure/msg/22186113b36041f1?hl=en But that got me thinking that "numbering" was just an instance of consuming from the (iterate inc 0) sequence. As