GNU Info

Info Node: (slib.info)Tree Operations

(slib.info)Tree Operations


Next: Chapter Ordering Prev: Common List Functions Up: Sorting and Searching
Enter node , (file) or (file)node

Tree operations
---------------

  `(require 'tree)'

  These are operations that treat lists a representations of trees.

 - Function: subst new old tree
 - Function: subst new old tree equ?
 - Function: substq new old tree
 - Function: substv new old tree
     `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.

     `substq' and `substv' are similar, but test against OLD using
     `eq?' and `eqv?' respectively.  If `subst' is 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))

 - Function: copy-tree tree
     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


automatically generated by info2www version 1.2.2.9