本文介绍了如何创建Clojure拉链的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用Clojure Zipper( vector-zip
)创建以下图形:
A
/ | \
BCD
/ \
EF
尝试了
(vector-zip [A[BCD[EF ]]])
它返回
[[A[BCD[EF]]] nil]
$
解决方案是的,这是正确的。p $ p>
您的代码的一些测试:
(require'[clojure.zip:as zip])
(def zv(zip / vector-zip [A[BCD[EF]]]))
( - > zv zip /下一个) ; => [A{:l [],:pnodes [[A[BCD[EF]]]],:ppath nil,:r CD[EF]])}]
( - > zv zip / next zip / node); => A
( - > zv zip / next zip / next zip / next zip / node); => B
( - > zv zip / next zip / next zip / children); => (BCD[EF])
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?
解决方案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"])
这篇关于如何创建Clojure拉链的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!