On Jun 13, 11:07 pm, James Reeves <weavejes...@googlemail.com> wrote:
> For instance, lets say I want to return a lazy list of all the lines
> in all the files in a directory tree:
>
>   (use '(clojure.contrib java-utils
>                          duck-streams))

When clojure.contrib releases version 1.0, that might be an option.

>   (defn all-line-seq [dir]
>     (mapcat read-lines (file-seq (file dir))))
>
> Since file-seq, read-lines and mapcat all lazy, my final result is
> lazy as well.

Seems to me that unless you completely consume the sequence, it will
leak a file handle.

> > Is file-seq recursive? I'd figured it just returned the flat contents
> > of a directory.
>
> Yep, it's recursive.

OK. Even so, the implementation in terms of super-lazy-seq shows the
power of that macro. Mostly, I'm doing quite a few things with I/O
that require custom next-item-in-seq generators for the records or
other objects returned, for which it's coming in real handy. In those
circumstances lazy-seq saves the bother of doing a loop/recur in
everyplace that consumes some records, and super-lazy-seq in turn lets
me still use a loop/recur style in the one place where the code
extracts and grovels over the records one by one.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to