为什么解构在 Clojure 中对 walk 而不是 postwalk 有效?

Why does destructuring work for walk but not postwalk in Clojure?

我可以使用 Clojure 中的 walk 遍历以下地图的顶层:

(use 'clojure.walk)
(walk (fn [[k v]] (println (type k) k v)) identity {:a 1 :b {:c 3}})

结果:

clojure.lang.Keyword :b {:c 3}
clojure.lang.Keyword :a 1
{}

(这与 map 的工作方式非常相似)

但是当我使用 postwalk - 它在尝试解构时爆炸了:

(postwalk (fn [[k v]] (println (type k) k v)) {:a 1 :b {:c 3}})

结果:

UnsupportedOperationException nth not supported on this type: Keyword  clojure.lang.RT.nthFrom (RT.java:857)

也许看看步行后会发生什么可以阐明您的问题。

user=> (postwalk println {:a 1 :b {:c 3}})
:a
1
[nil nil]
:b
:c
3
[nil nil]
{}
[nil nil]
{}
nil
user=>