These are operations that treat lists a representations of trees.
subst makes a copy of tree, substituting new for
every subtree or leaf of tree which is
equal? to old
and returns a modified tree. The original tree is unchanged, but
may share parts with the result.
substv are similar, but test against old
eqv? respectively. If
called with a fourth argument, equ? is the equality predicate.
(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
eq? to the original ones – only the leaves are.
(define bar '(bar)) (copy-tree (list bar 'foo)) ⇒ ((bar) foo) (eq? bar (car (copy-tree (list bar 'foo)))) ⇒ #f