On Mon  7 Apr 2014 at 11:07:37AM -0700, Simon Brooke wrote:
> OK, the second question I've sort of answered for myself, by riffing on the 
> source of line-seq:
> 
> (defn expr-seq
>   "Returns forms from src (assumed to be Clojure source) as a lazy sequence 
> of expressions"
>   [^java.io.PushbackReader src]
>   (when-let [expr (read src)]
>     (try
>       (cons expr (lazy-seq (expr-seq src)))
>       (catch RuntimeException eof))))
> 
> However, line-seq doesn't bother with catching an exception (presumably 
> because it's not using a PushbackReader). So I come back to my first 
> question: how do I detect the end of a file?

Use clojure.core/read with three params: [stream eof-error? eof-value]
From the Slamhound source:

(take-while #(not= ::done %) (repeatedly #(read rdr false ::done)))

    guns

Attachment: pgpOWqGF7SNcJ.pgp
Description: PGP signature

Reply via email to