Re: OutOfMemoryError with loop/recur

2009-09-21 Thread Tassilo Horn
John Harrop writes: Hi John, >> Although that doesn't really help, the normal `reduce' doesn't do >> better. >> >> (reduce + (take 100 (iterate inc 1))) ; works >> (reduce + (take 1000 (iterate inc 1))) ; OutOfMemoryError > > Are you sure? I'd expect that with > > (def integers (iterat

Re: OutOfMemoryError with loop/recur

2009-09-19 Thread Rosen K
How about: (defn limited-reduce [f coll n] (reduce f (take n coll))) Rosen On Sep 18, 10:52 pm, Patrik Fredriksson wrote: > Hi! > > Could someone please help me understand why the following causes a > java.lang.OutOfMemoryError: Java heap space for large n:s (10 > works fine, 100 do

Re: OutOfMemoryError with loop/recur

2009-09-18 Thread Laurent PETIT
2009/9/18 ajuc > > I was probably wrong - too many classes should throw error about > permGenSpace (at least in java they do). > Yes. A literal (fn) will only create one class. And returning it 100.000 times in a tight loop will create 100.000 instances of this class. > > Also for me it works

Re: OutOfMemoryError with loop/recur

2009-09-18 Thread Patrik Fredriksson
On Sep 18, 10:46 pm, John Harrop wrote: > On Fri, Sep 18, 2009 at 4:39 PM, Tassilo Horn wrote: > > > Although that doesn't really help, the normal `reduce' doesn't do > > better. > > > (reduce + (take 100 (iterate inc 1)))  ; works > > (reduce + (take 1000 (iterate inc 1))) ; OutOfMemoryE

Re: OutOfMemoryError with loop/recur

2009-09-18 Thread John Harrop
On Fri, Sep 18, 2009 at 3:52 PM, Patrik Fredriksson wrote: > > Hi! > > Could someone please help me understand why the following causes a > java.lang.OutOfMemoryError: Java heap space for large n:s (10 > works fine, 100 does not). > > (def integers (iterate inc 1)) > > (defn limited-reduce

Re: OutOfMemoryError with loop/recur

2009-09-18 Thread John Harrop
On Fri, Sep 18, 2009 at 4:39 PM, Tassilo Horn wrote: > Although that doesn't really help, the normal `reduce' doesn't do > better. > > (reduce + (take 100 (iterate inc 1))) ; works > (reduce + (take 1000 (iterate inc 1))) ; OutOfMemoryError Are you sure? I'd expect that with (def integ

Re: OutOfMemoryError with loop/recur

2009-09-18 Thread Jonathan Smith
It would be kind of nice to have some sort of uniform identifier for laziness similar to ! for destructive and ? for predicate. On Sep 18, 5:10 pm, Raoul Duke wrote: > > Runs (in a nice constant memory) even though yours (which almost > > appears equivalent) will not! > > i am thinking ever more

Re: OutOfMemoryError with loop/recur

2009-09-18 Thread Raoul Duke
> Runs (in a nice constant memory) even though yours (which almost > appears equivalent) will not! i am thinking ever more that less than stupendously overt syntax for laziness is too risky cf. Haskell and Clojure. sincerely. --~--~-~--~~~---~--~~ You received th

Re: OutOfMemoryError with loop/recur

2009-09-18 Thread Jonathan Smith
http://www.haskell.org/haskellwiki/Performance These are the performance tips I was referring to. (4. General techniques, laziness, space leaks.) On Sep 18, 5:03 pm, Jonathan Smith wrote: > Hi! > > This is happening because you have integers saved to a global > variable. > > (iterate inc 1) cre

Re: OutOfMemoryError with loop/recur

2009-09-18 Thread Jonathan Smith
Hi! This is happening because you have integers saved to a global variable. (iterate inc 1) creates an infinite lazy seq. Def-fing it to a global says 'Hey, i might want this later!' to Clojure. This means that as you take numbers from integers; they get saved in memory rather than being garba

Re: OutOfMemoryError with loop/recur

2009-09-18 Thread Patrik Fredriksson
Hi, On Sep 18, 10:39 pm, Tassilo Horn wrote: > Patrik Fredriksson writes: > > Hi Patrick, > > > > > Could someone please help me understand why the following causes a > > java.lang.OutOfMemoryError: Java heap space for large n:s (10 > > works fine, 100 does not). > > > (def integers (it

Re: OutOfMemoryError with loop/recur

2009-09-18 Thread Patrik Fredriksson
On Sep 18, 10:35 pm, Jarkko Oranen wrote: > On Sep 18, 10:52 pm, Patrik Fredriksson wrote: > > > > > Hi! > > > Could someone please help me understand why the following causes a > > java.lang.OutOfMemoryError: Java heap space for large n:s (10 > > works fine, 100 does not). > > > (def

Re: OutOfMemoryError with loop/recur

2009-09-18 Thread Tassilo Horn
Patrik Fredriksson writes: Hi Patrick, > Could someone please help me understand why the following causes a > java.lang.OutOfMemoryError: Java heap space for large n:s (10 > works fine, 100 does not). > > (def integers (iterate inc 1)) > > (defn limited-reduce [fn coll n] > (loop [c c

Re: OutOfMemoryError with loop/recur

2009-09-18 Thread ajuc
I was probably wrong - too many classes should throw error about permGenSpace (at least in java they do). Also for me it works for n=100, fails for 1000 (clojurebox 1.0). --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Goog

Re: OutOfMemoryError with loop/recur

2009-09-18 Thread Jarkko Oranen
On Sep 18, 10:52 pm, Patrik Fredriksson wrote: > Hi! > > Could someone please help me understand why the following causes a > java.lang.OutOfMemoryError: Java heap space for large n:s (10 > works fine, 100 does not). > > (def integers (iterate inc 1)) > > (defn limited-reduce [fn coll n]

Re: OutOfMemoryError with loop/recur

2009-09-18 Thread ajuc
I'm beginner myself, but I' think it's because it creates 100 new classes (for each new anonymous fn). --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@g

OutOfMemoryError with loop/recur

2009-09-18 Thread Patrik Fredriksson
Hi! Could someone please help me understand why the following causes a java.lang.OutOfMemoryError: Java heap space for large n:s (10 works fine, 100 does not). (def integers (iterate inc 1)) (defn limited-reduce [fn coll n] (loop [c coll i n result 0] (if (zero? i) result (rec