views:

205

answers:

1

I have a function that reads one token from an input stream that is called (get-next-indicator stream indicator) and returns it. I am trying to use it to construct a map.

But, when I run it, it locks up. If I remove one of the get-next-indicator function, it does work. Does both functions try to read the stream at the same time is this. What is causing this?


(defn decode-map [ stream ]
  (loop [result {}]
    (let [c (char (.read stream))]
      (if (= c \e)
        result
        (recur (assoc result (get-next-indicator stream (int c))
                             (get-next-indicator stream (int c)) ))))))
+1  A: 

Just a guess, but does get-next-indicator block if there's nothing on the stream to get? You're calling it twice in succession before the recur (and then doing a .read after that to detect the end). If the stream ran out of bytes during either of the get-next-indicator calls, then the function would hang, waiting for enough bytes on the stream to finish out those calls.

Greg Harman