Re: Problem with lazy-seq and heap space overflow

2011-01-22 Thread Tom Hall
Hi Marek, I too am a mostly Python guy looking at clojure. I think you will like the for macro as it is a lot like list comprehensions. I did Euler45 in clojure too and https://github.com/thattommyhall/Project-Euler/blob/master/45.clj runs in 700ms I thought it was quite a nice soln: triangles, he

Re: Problem with lazy-seq and heap space overflow

2011-01-20 Thread Ken Wesson
On Thu, Jan 20, 2011 at 10:30 PM, gaz jones wrote: > interesting... the changes i suggested cause it to get the first 3 > values in around 300ms on my machine and dont blow the heap O_o Yes; I'm not sure why but the lazy-seq version is significantly faster than iterate, though the latter is inter

Re: Problem with lazy-seq and heap space overflow

2011-01-20 Thread gaz jones
interesting... the changes i suggested cause it to get the first 3 values in around 300ms on my machine and dont blow the heap O_o On Thu, Jan 20, 2011 at 8:38 PM, Ken Wesson wrote: > My suspicion is that > > (lazy-seq ... (map rest seqs)) > > in closing over seqs causes the heads of the seqs to

Re: Problem with lazy-seq and heap space overflow

2011-01-20 Thread Ken Wesson
My suspicion is that (lazy-seq ... (map rest seqs)) in closing over seqs causes the heads of the seqs to be held during the recur iteration. When the third value is as big as 1533776805, the recur iteration is realizing lengthy portions of the seqs downstream. The problem with this is that the l

Re: Problem with lazy-seq and heap space overflow

2011-01-20 Thread gaz jones
try this: (defn equal-values [seqs] "Given a list of ascending sequences, returns a lazy sequence containing only values that exist in all of the sequences." (lazy-seq (if (empty? (first seqs)) [] (let [first-values (map first seqs)] (if (apply = first-values) (cons (fir

Problem with lazy-seq and heap space overflow

2011-01-20 Thread Marek Stępniowski
Hi, I'm Marek Stępniowski, a Python developer trying to learn a new language by night. I'm new to this group. When solving problem 45 from Project Euler [1] I have tried to learn how lazy-seq macro should be used and wrote the code below:: (defn pentagonal-numbers [] (map #(* 1/2 % (dec (* 3 %))