How to create Clojure Zipper

孤街醉人 提交于 2020-01-15 03:56:20

问题


How could I create the following graph using Clojure Zipper (vector-zip):

   A
 / | \      
B  C  D
     / \
    E   F

I have tried

(vector-zip ["A" ["B" "C" "D"["E" "F"]] ])

It returns

[["A" ["B" "C" "D" ["E" "F"]]] nil]

Is it right?


回答1:


Yes it's right. Some tests of your code:

(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"])


来源:https://stackoverflow.com/questions/28427383/how-to-create-clojure-zipper

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!