Demonstrations of how clojure.core/concat
can produce a
StackOverflow.
This is the most obvious case: A loop that builds up a sequence by concatenation.
I’ve seen this fairly often in application code, usually from less-experienced Clojure programmers. It’s easy to fix by forcing the sequence into a vector.
Experienced Clojure programmers have learned not to do this.
(defn build-lists
"Returns a concatenated sequence of ranges."
[n]
(loop [i 0
out nil]
(if (> i n)
out
(recur (inc i)
(concat out (range i))))))
(build-lists 6)
(first (build-lists 4000))
(pst *e)
Hi, I think I'm having this problem. Could you post the correct way to do it, too? Thanks!