Christophe, thanks for your explanation. I certainly agree that is what is happening but I find it unintuitive, especially when the structure I was walking was an S-expression in which the first member of a list is understood to be an operator to which the following members are passed as arguments. As I dust off my memories of how e.g. linked lists work I see that the (- 1 2) list itself would be the first link, and then the that list has links to the -, the 1, and the 2.
I guess that perhaps the takeaway from this is that an example illustrating this would be a useful addition to the API doc (the doc does discuss "branch" but it wasn't clear what the definition of branch was - as per my misunderstanding). On Jan 18, 4:36 pm, Christophe Grand <christo...@cgrand.net> wrote: > 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 -~----------~----~----~----~------~----~------~--~---