Hi, Am 09.05.2009 um 13:06 schrieb Mark Reid:
; ---- Begin lazyread.clj ----
(import '(java.io FileReader BufferedReader PrintWriter))
(def filename "test.data")
; Write out a small test file. Numbers 0 to 99, one per line.
(with-open [data (PrintWriter. filename)]
(dotimes [i 100] (.println data i)))
; An attempt at capturing the general idiom that doesn't work
(defn cons-while
[pred f]
(lazy-seq
(when pred
(cons f (cons-while pred f)))))
; ---- End lazyread.clj ----
There is a mistake in this function: pred should be (pred)
as well as f should be (f).
Furthermore I would call it repeatedly-while.
(defn repeatedly-while
[pref f]
(lazy-seq
(when (pred)
(cons (f) (cons-while pred f)))))
Then this should work:
(repeatedly-while #(.ready reader) #(.readLine reader))
I didn't test it, though.
Sincerely
Meikel
smime.p7s
Description: S/MIME cryptographic signature
