>(use 'clojure.walk)
>(def thing {:page/tags [{:tag/category "lslsls"}]})
>(postwalk #(println %) thing)
:page/tags
:tag/category
lslsls
[nil nil]
{}
[nil]
[nil nil]
{}
=> nil
我不确定为什么打印出来
[nil nil]
{}
[nil]
[nil nil]
{}
因为我是Clojure的新手,也许是我失踪的东西。任何帮助将不胜感激。
答案 0 :(得分:1)
您可能已经预料到了
user=> (clojure.walk/postwalk-demo thing)
Walked: :page/tags
Walked: :tag/category
Walked: "lslsls"
Walked: [:tag/category "lslsls"]
Walked: {:tag/category "lslsls"}
Walked: [{:tag/category "lslsls"}]
Walked: [:page/tags [{:tag/category "lslsls"}]]
Walked: {:page/tags [{:tag/category "lslsls"}]}
{:page/tags [{:tag/category "lslsls"}]}
由于walk替换每个子表单所使用函数的返回值,因此需要在打印后返回子表单的副本,如
user=> (source clojure.walk/postwalk-demo)
(defn postwalk-demo
"Demonstrates the behavior of postwalk by printing each form as it is
walked. Returns form."
{:added "1.1"}
[form]
(postwalk (fn [x] (print "Walked: ") (prn x) x) form))