Timothy Pratley a écrit :
> I want to grow a tree programmatically so have been trying zippers:
>
> (defn insert-parent [loc n]
>   (clojure.zip/replace loc (clojure.zip/make-node
>                              loc n loc)))
> (println (clojure.zip/root (insert-parent (clojure.zip/seq-zip (list
> 1)) 2)))
> (println (clojure.zip/root (clojure.zip/append-child
>                              (clojure.zip/seq-zip (list 1)) 2)))
>
> [(1) nil]
> (1 2)
>
> My 'insert-parent' function does not work, I was trying to get (2 1) -
> any tips?
>   

It's clojure.zip/insert-child you are looking for:

clojure.contrib.struct-ed=> (clojure.zip/root (clojure.zip/insert-child 
(clojure.zip/seq-zip (list 1)) 2))
(2 1)

Christophe

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to