Re: Map holds on to element being processed

2014-11-11 Thread 'Matt Bossenbroek' via Clojure
Thanks! I was playing around with similar variants last night & came up with some that seem to work for one element, but not many. I was seeing a similar result from your version: => (map2 count [(repeat 1e8 "stuff") (repeat 1e8 "stuff") (repeat 1e8 "stuff")]) OutOfMemoryError GC overhead limi

Re: Map holds on to element being processed

2014-11-10 Thread Andy Fingerhut
At least in your particular case, replacing map with map2, defined below as a small modification to a subset of map, seems to do the trick: (defn map2 [f coll] (lazy-seq (when-let [s (seq coll)] (let [r (rest s)] (cons (f (first s)) (map2 f r)) (map2 count [(repeat 1e8 "stuff

Map holds on to element being processed

2014-11-10 Thread 'Matt Bossenbroek' via Clojure
Ran into an interesting problem today. In short, this works: (count (repeat 1e8 "stuff")) But this doesn't: (map count [(repeat 1e8 "stuff")]) To be fair, given sufficient memory, it would eventually complete. (If the second example does work for you, change it to 1e10 or something higher).