I am trying to read a TCP request via an instance of DataInputStream and am 
running into this error with the following code:

(defn receive
  [socket]
  (with-open [reader (DataInputStream. (.getInputStream socket))]
    (let [length   (read-length reader)
          bytes-in (byte-array length)
          offset   (atom 0)
          index    (atom 0)]
      (while (not= -1 @offset)
        (reset! offset (.read reader bytes-in offset (- length index)))
        (reset! index (+ index offset))))))

For some reason, trying to update the value in offset appears to result in 
this casting error. I tried testing a similar expression at the REPL, and 
it works, e.g.

> (def blah (atom 0))
> (reset! blah 93)    ; no error

It seems odd that Clojure would complain about this, since "93" is an 
instance of java.lang.Long -- why would Clojure be so annoyingly 
anal-retentive when setting the atom to a java.lang.Num? Also, if anyone 
has any ideas on how to make achieve this without using atoms, and what the 
best approach would be (a recursive solution using loop-recur, perhaps?)

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