I have an innocent-looking function that only uses map and reduce, but
when I run it on a big collection (10K elements) I get a StackOverflow
exception. Here is the function:

(defn multi-filter [filters coll]
  (reduce
    (fn [res e]
      (map (fn [f r] (if (f e) (conj r e) r))
        filters
        res))
    (repeat (count filters) [])
    coll))

And here is how you can reproduce the problem:
(let [[a b c] (multi-filter [even? odd? even?] (range 10000))])

NOTE: specify java -Xmx512m to avoid heap overflow first.

The problem is with map, and if I replace it with my own eager map the
code runs fine:
(defn emap [f c1 c2]
  (loop [s1 (seq c1) s2 (seq c2) res [] ]
    (if (and s1 s2)
      (recur (next s1) (next s2) (conj res (f (first s1) (first s2))))
      res)))

Here is what feels wrong to me: I do expect lazy seq generated my
standard map fn to consume somewhat unpredictable HEAP space at
unpredictable moments, but I totally don't expect it to run out of
STACK space.
Is this something that can be fixed in Clojure library, or do you
think "it's by design"?

I'm running the latest 1.1 alpha build.

- Dmitry

--~--~---------~--~----~------------~-------~--~----~
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