lazy slurp

8 views
Skip to first unread message

a r

unread,
Apr 16, 2008, 7:07:08 PM4/16/08
to clo...@googlegroups.com
(defn char-seq
([]
(char-seq *in*))
([stream]
(char-seq stream false))
([stream close?]
(let [ch (. stream (read))]
(if (== ch -1)
(when close? nil)
(. stream (close)))
(lazy-cons (char ch) (char-seq stream close?))))))

(defn char-seq-from-file
[#^String f]
; (with-open r (new java.io.FileReader f) ;; throws an error
(let [r (new java.io.FileReader f)]
(char-seq r true)))

Does this code guarantees closing the file when an exception occurs?
"Slurp" does ("with-open" macro). "Line-seq" is not.

Is there any way of wrapping lazy code with "try" form?

Cheers,
-r.

Reply all
Reply to author
Forward
0 new messages