Greg Harman a écrit :
> Take the following data structure, wrapped up with clojure.zip/seq-
> zip: '(+ (- 1 2) (* 3 4))
>
> Repeatedly calling clojure.zip/next produces these "nodes":
>
> +
> (- 1 2)
> -
> 1
> 2
> ...
>
> The (- 1 2) is what's throwing me off. Drawing out a tree structure, I
> see that my nodes are + - 1 2 * 3 4 and the structure (- 1 2) is a
> group of nodes (arranged as a subtree), but shouldn't be a node
> itself.
>   
+ - 1 2 * 3 4 are leaves (nodes with no children)

(- 1 2) is a node with 3 children: -, 1 and 2.

(+ (- 1 2) (* 3 4)) is a node with 3 children: +, (- 1 2) and (* 3 4).
> To continue what I actually want to accomplish: if I call next while
> loc is currently on the +, I expect to see - as my node. 
You can test with branch? to test if a node has children or not.
Something like (first (drop-while branch? (iterate next loc))) must 
yield the next leaf.

> If I then
> call remove, I expect it to remove the whole sub-tree (- 1 2), since
> minus is a parent of 1 and 2.
>   
minus is a sibling of 1 and 2. If you call remove while on it, the 
resulting tree is:
(+ (1 2) (* 3 4))
To remove (- 1 2) you have to be on the node (- 1 2).

Hope this helps.

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