(require 'tree)
These are operations that treat lists a representations of trees.
substmakes a copy of tree, substituting new for every subtree or leaf of tree which isequal?to old and returns a modified tree. The original tree is unchanged, but may share parts with the result.
substqandsubstvare similar, but test against old usingeq?andeqv?respectively. Ifsubstis called with a fourth argument, equ? is the equality predicate.Examples:
(substq 'tempest 'hurricane '(shakespeare wrote (the hurricane))) ⇒ (shakespeare wrote (the tempest)) (substq 'foo '() '(shakespeare wrote (twelfth night))) ⇒ (shakespeare wrote (twelfth night . foo) . foo) (subst '(a . cons) '(old . pair) '((old . spice) ((old . shoes) old . pair) (old . pair))) ⇒ ((old . spice) ((old . shoes) a . cons) (a . cons))
Makes a copy of the nested list structure tree using new pairs and returns it. All levels are copied, so that none of the pairs in the tree are
eq?to the original ones – only the leaves are.Example:
(define bar '(bar)) (copy-tree (list bar 'foo)) ⇒ ((bar) foo) (eq? bar (car (copy-tree (list bar 'foo)))) ⇒ #f