On 2 March 2010 23:57, TimDaly <[email protected]> wrote:
> 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

Works for me after fixing the argument list (as mentioned by Meikel)
and closing the parenthesis in the let vector.  I also changed (new
Blah something) to (Blah. something) and (. object (method)) to
(.method object) but those should not make a difference:

user=> (defn reader [file] (let [in (java.io.FileInputStream. file)]
#(.read in)))
#'user/reader
user=> (def fetchbyte (reader "/etc/shells"))
#'user/fetchbyte
user=> (fetchbyte)
35
user=> (fetchbyte)
32
user=> (fetchbyte)
47

-- 
Michael Wood <[email protected]>

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

Reply via email to