如何使用Clojure Zipper(vector-zip
)创建以下图表:
A
/ | \
B C D
/ \
E F
我试过了
(vector-zip ["A" ["B" "C" "D"["E" "F"]] ])
返回
[["A" ["B" "C" "D" ["E" "F"]]] nil]
是不是?
答案 0 :(得分:2)
是的,这是对的。您的代码的一些测试:
(require '[clojure.zip :as zip])
(def zv (zip/vector-zip ["A" ["B" "C" "D"["E" "F"]]]))
(-> zv zip/next) ; => ["A" {:l [], :pnodes [["A" ["B" "C" "D" ["E" "F"]]]], :ppath nil, :r (["B" "C" "D" ["E" "F"]])}]
(-> zv zip/next zip/node) ; => "A"
(-> zv zip/next zip/next zip/next zip/node) ; => "B"
(-> zv zip/next zip/next zip/children) ; => ("B" "C" "D" ["E" "F"])