2010/11/3 John Szakmeister <j...@szakmeister.net>: > I'm sorry... I don't quite understand this explanation. Do you mean > that reduce is realizing the entire list all at once? I would think > it would grab an element one at a time. Sorry for the stupid > question, but there's something subtle here that I'm not > understanding. > >> user=> (reduce #(doall (map + %1 %2)) (partition 5 (range 1e6))) >> (99999500000 99999700000 99999900000 100000100000 100000300000) > > Is it because of the way the lazy sequence is being generated? Would > different implementations of partition or range do better? > > Thanks in advance! > > -John
I think the problem is that this reduction will build an expression like this: (map + ... (map + ... (map + ... (map + ... <one million nesting levels>)))) When clojure tries to realize an element of the resulting lazy seq, every level will result in a nested method call, which will eventually blow the stack. // raek -- 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