4 ms·
> They can be useful for certain constructions, but they don’t really enable anything amazing that you can’t do otherwise, just with a slightly different algori
by arohner 14y ago
> They can be useful for certain constructions, but they don’t really enable anything amazing that you can’t do otherwise, just with a slightly different algorithm.
One really nice property of laziness is dealing with data larger than RAM. A couple of months ago I wrote some ML processing of the wikipedia XML in Clojure. In about 5 lines, I had a lazy sequence of every <Article> tag from the XML. Then I can (map my-fn all-articles-from-wikipedia), without blowing the heap (the wikipedia XML was like ~10GB, zipped).
Yes, it's possible to do non-lazy, but this was cleaner and simpler.
One algorithmic advantage of lazy seqs is that (map foo (map bar (map baz my-big-seq))) makes only one pass over the data, as opposed to 3 when non-lazy.
- mark_l_watson 14y ago+1 Allen, great example! I also have a side project where I am making multiple sweeps thought the wikipedia XML data. I did this in Ruby using a streaming XML parser, but I am going to try your approach.