I would like to have a function that returns the next binary byte of a
file.
I tried

(defn reader (file)
  (let [in (new java.io.FileInputStream file]
    #(. in (read))))

The idea is that I could call this function once and it would return a
closure
over the 'in' object. Then I could simply call reader to get the next
byte. As in

(def fetchbyte (reader "file.o"))

(fetchbyte)

I get an error
java.lang.IllegalArgumentException: Don't know how to create ISeq
from:
clojure.lang.Symbol

I've tried several other paths. From the REPL I can type
(def in (new java.io.FileInputStream "file.o"))
(def fetchbyte #(. in (read)))
(fetchbyte)

and it all works fine. Is there a way to return a closure in Clojure?

I tried using a lazy-cons to make a lazy stream but that also failed.
I tried (seq (. in (read))) to generate an iterator-style walker but
that failed.

Tim Daly

-- 
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

Reply via email to