如何创建Clojure Zipper

时间:2015-02-10 08:48:39

标签: clojure zipper

如何使用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]

是不是?

1 个答案:

答案 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"])