1

我有一个函数,它从称为(get-next-indicator 流指示器)的输入流中读取一个标记并返回它。我正在尝试使用它来构建地图。

但是,当我运行它时,它会锁定。如果我删除 get-next-indicator 函数之一,它确实有效。这两个函数是否尝试同时读取流是这样的。这是什么原因造成的?


(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)) ))))))
4

1 回答 1

1

只是一个猜测,但如果流中没有任何东西可以获取,get-next-indicator 会阻塞吗?您在重复之前连续调用它两次(然后在之后执行 .read 以检测结束)。如果在任一 get-next-indicator 调用期间流用完了字节,则函数将挂起,等待流上足够的字节来完成这些调用。

于 2009-07-01T02:38:32.303 回答