Ok, now by now i think to have understand...

To do right, I should build a macro similar to let where I pass the
filename and after execute the body close the stream, right ?

On Dec 13, 9:42 pm, Cedric Greevey <cgree...@gmail.com> wrote:
> On Tue, Dec 13, 2011 at 10:14 PM, Simone Mosciatti <mweb....@gmail.com> wrote:
> > No, I'm sure to not use all the sequence, so I will follow your second
> > advice, but...
>
> > Cause of my non-perfect english I've not really understand the last
> > part.
> >  Who is the caller ?
> >  You suggest something like this:
>
> > (let [fl (clojure.java.io/reader "path/filename")
> >      rd (lazy-reader fl)]
> > (do-my-operation-with-lazy-reader)
> > (.close fl))
>
> > ???
>
> Pretty much, yes. The lazy-reader function will of course not call
> clojure.java.io/reader on its argument, instead just passing it
> directly to its internal function lr. And if
> (do-my-operation-with-lazy-reader) returns a lazy sequence that's
> backed by the lazy-reader sequence, then either it needs to be doall'd
> before (.close fl) or the responsibility for creating and closing the
> reader needs to be pushed up to *its* user. Generally, if dealing with
> data that might not fit in main memory you'd need to push the reader's
> lifetime management up to the level where you're not just wrapping the
> seq but reducing over it, searching it for an item (with something
> like (first (filter ...)) or (first (remove ...)) or (last ...) or
> (some ...)), or picking a limited sample (e.g. (take
> some-finite-number (filter foo (some-wrapped-lazy-reader-seq rdr)))).

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