Thank you, that's neat!

On Monday, 7 April 2014 19:14:40 UTC+1, guns wrote:
>
> 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 
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to