Hi I recently started to dig into lazy sequences processing in clojure because I need to process huge amount of data that doesn't fit in memory. I found a few articles and examples describing the way lazy seqs work in clojure. But so far all I got myself is a paranoia. Now everywhere I look in the code I have a feeling that it's gonna retain my sequence in memory. It seems like realization of lazy clojure sequences is very unclear sometimes and you can't reason about it.
For example: (let [r (range 1e9)] (first r) (last r)) ;;=> 999999999 (let [r (range 1e9)] (last r) (first r)) ;;=> java.lang.OutOfMemoryError: GC overhead limit exceeded I got this example from here https://github.com/danielmiladinov/joy-of-clojure/blob/master/src/joy-of-clojure/chapter6/laziness.clj I tried it myself and it works as it's commented above. But how in the world does it work internally? How can I reason about this code in more complex example where instead of function first there is some function x and instead of function last there is some function y. I can't come up with some clear rule of thumb that would help me to be confident that my code works well on lazy collections without running it and checking whether it throws OOME or not.. I would appreciate if anyone could point me to any discussion/article/paper that makes things more clear? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
