On Monday, April 7, 2014 1:14:40 PM UTC-5, 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
>
If using clojure.edn, which might be a good idea here, the syntax is
slightly different for specifying an EOF marker, e.g.
(let [sentinel (Object.)]
(take-while #(not= sentinel %) (repeatedly #(edn/read {:eof sentinel}
file))))
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.