Patrik Fredriksson <patri...@gmail.com> writes:

Hi Patrick,

> Could someone please help me understand why the following causes a
> java.lang.OutOfMemoryError: Java heap space for large n:s (100000
> works fine, 1000000 does not).
>
> (def integers (iterate inc 1))
>
> (defn limited-reduce [fn coll n]
>   (loop [c coll i n result 0]
>   (if (zero? i)
>     result
>   (recur
>     (rest c)
>     (dec i)
>     (fn result (first c))))))
>
> (limited-reduce + integers 100000)

Although that doesn't really help, the normal `reduce' doesn't do
better.

(reduce + (take 1000000 (iterate inc 1)))  ; works
(reduce + (take 10000000 (iterate inc 1))) ; OutOfMemoryError

Bye,
Tassilo

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to