Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Clojure 如何解析postwalk表单参数_Clojure - Fatal编程技术网

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