Like clojure.core/line-seq but opens f with reader. Automatically
closes the reader AFTER YOU CONSUME THE ENTIRE SEQUENCE.
(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))))
Comments top
1 comment(s) for read-lines.
If you are running this in an emacs slime repl, you may need to add the following lines to you .emacs file, otherwise you'll get odd errors when reading a unicode file.
(set-language-environment "UTF-8")(setq slime-net-coding-system 'utf-8-unix)
(set-language-environment "UTF-8") (setq slime-net-coding-system 'utf-8-unix)