use-output-stream-1
use-output-stream-2
按预期工作,并且已验证书面文件。我不明白huffman.core> (use-output-stream-1)
nil
huffman.core> (rb "01010101")
85
huffman.core> (use-output-stream-2)
IllegalArgumentException No matching method found: write for class java.io.BufferedOutputStream clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:80)
huffman.core>
会抛出错误。
(defmacro rb-macro [b]
`(unchecked-byte (Integer/parseInt ~b 2)))
(defn use-output-stream-3 []
(with-open [o (output-stream path)]
(.write o (unchecked-byte 255))
(.write o (rb-macro "01010101"))
))
修改即可。我认为这与评估顺序有关,所以我写了一个宏。
(rb "01010101")
这似乎可以解决问题,但我想了解发生了什么。我不明白为什么.write
未首先评估,然后结果传递给25.0.1