Just in case I'll mention that Meikel's use of (with-open) will automatically close the reader.
On May 19, 11:40 am, dokondr <[email protected]> wrote: > On May 19, 6:52 pm, Meikel Brandmeyer <[email protected]> wrote: > > > Hi, > > > something like the following should work. > > > (with-open [rdr (java.io.FileReader. "file.txt")] > > (doseq [line (line-seq rdr) > > word (.split line "\\s")] > > (when (.endsWith word "ing") > > (println word)))) > > > Sincerely > > Meikel > > Thanks everybody! The short one from Meikel (above) looks nice to > me :) > > And the one from ClojureDocs too: > > (defn read-lines > "Like clojure.core/line-seq but opens f with reader. Automatically > closes the reader AFTER YOU CONSUME THE ENTIRE SEQUENCE." > [f] > (let [read-line (fn this [^BufferedReader rdr] > (lazy-seq > (if-let [line (.readLine rdr)] > (cons line (this rdr)) > (.close rdr))))] > (read-line (reader f)))) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en
