On Sun, Mar 1, 2009 at 11:06 PM, max3000 <maxime.lar...@gmail.com> wrote: > > Hi, > > I find the laziness in clojure very hard to wrap my head around. I > understand the idea and it's probably nice in theory. However, in real > life it doesn't seem really useful beyond hardcore mathematical > problems.
I felt the same way at first. I think it would help if the group shared some common, non-mathematical cases, where laziness is helpful. I'll share this one which is described near the end of the section on "Input/Output" at http://www.ociweb.com/mark/clojure/article.html#IO. The line-seq function takes a java.io.BufferedReader and returns a lazy sequence of all the lines of text in it. The significance of returning a lazy sequence is that it doesn't really read all of the lines when it is called. That could consume too much memory. Instead it reads a line each time one is requested from the lazy sequence. Another way to think about this is that it allows writing functions that return all the data a caller might want without having to know ahead of time how much each caller might want. It may be the case that a caller just wants the first piece of data or three pieces or all of them. As the writer of the function that returns the data, you don't have to care about that. -- R. Mark Volkmann Object Computing, Inc. --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---