draining file of s-expressions

2011-01-14 Thread Mike
Let's say I've got a finite, unknown number of valid clojure forms in a file, say like this: (foo)(bar)[blah blah blah](and one more) (note there is a vector sandwiched in there too) Let's say I open this file and want to use it with read: (read f) = (foo) I do it again, and: (read f) = (bar)

Re: draining file of s-expressions

2011-01-14 Thread Meikel Brandmeyer
Hi, you can use lazy-seq: (def eof-marker (Object.)) (defn read-all [stream] (lazy-seq (let [x (read stream false eof-marker)] (when-not (identical? x eof-marker) (cons x (read-all stream)) Or go for high-level: (def eof-marker (Object.)) (defn read-all [stream]