Clojure 如何解析postwalk表单参数
我不知道为什么会打印出下面的内容Clojure 如何解析postwalk表单参数,clojure,Clojure,我不知道为什么会打印出下面的内容 >(use 'clojure.walk) >(def thing {:page/tags [{:tag/category "lslsls"}]}) >(postwalk #(println %) thing) :page/tags :tag/category lslsls [nil nil] {} [nil] [nil nil] {} => nil 因为我是Clojure的新手,也许我错过了什么。任何帮助都将不胜感激 你可能已经预料到
>(use 'clojure.walk)
>(def thing {:page/tags [{:tag/category "lslsls"}]})
>(postwalk #(println %) thing)
:page/tags
:tag/category
lslsls
[nil nil]
{}
[nil]
[nil nil]
{}
=> nil
因为我是Clojure的新手,也许我错过了什么。任何帮助都将不胜感激 你可能已经预料到了
[nil nil]
{}
[nil]
[nil nil]
{}
由于walks会替换每个子窗体所用函数的返回值,因此在打印子窗体后需要返回该子窗体的副本,如中所示
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"}]}
从doc
使用f的返回值代替原始的
,您的f是println,它返回nil
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))