chickadee » tree

tree

This is an implementation of John Cowan's tree library with the following additional procedures added.

tree-find

(tree-find pred tree default)

Walks the tree in preorder and exits out early when a node (a subtree or atom) matches pred. Returns the first matching node, not a copy but the real one. If there is on match, return default, which is a mandatory argument.

tree-find-equal?

(tree-find-equal? tree needle)

Like tree-find, but finds the first node that's equal? to the needle or returns #f as a default.

The reason you might need that is because many of the other operations in the library act on subtrees, not copies of subtrees. So this is a way for you to turn a copy into a reference to the original subtree.

tree-atoms-any?

(tree-atoms-any? pred tree)

Like tree-any?, but only consider atoms.

tree-atoms-every?

(tree-atoms-every? pred tree)

Like tree-every?, but only consider atoms.

tree-remove

(tree-remove pred tree)

Remove every node (whether subtrees or atoms) that matches pred.

Source code

https://idiomdrottning.org/tree.scm