Hi,

On Aug 4, 4:56 pm, Cameron <cpuls...@gmail.com> wrote:

> Not 100% on this, but this is what I do when reading files...
>
> (with-open [rdr (BufferedReader. (FileReader. file-name))]
>     (reduce conj [] (line-seq rdr)))

An easier way to do this is doall.

> That ensures that the whole seq is realized without closing the
> handle, but it also allows you to wrap the whole block with a take
> function if you only cared about the first few lines. As far as I
> know, this would still close the resources after whether you realize
> the whole sequence or only take part of it. Can someone who knows a
> bit better confirm?

When you place the take around the with-open block or around the
doall, the whole file will be read into memory and stay there until
the take sequence is fully realised. If you really want only a certain
number of lines of the file, you have to move the take into the doall
in the with-open.

Sincerely
Meikel

-- 
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