[HARLEQUIN][Common Lisp HyperSpec (TM)] [Previous][Up][Next]

Function COPY-TREE


copy-tree tree => new-tree

Arguments and Values:

tree---a tree.

new-tree---a tree.


Creates a copy of a tree of conses.

If tree is not a cons, it is returned; otherwise, the result is a new cons of the results of calling copy-tree on the car and cdr of tree. In other words, all conses in the tree represented by tree are copied recursively, stopping only when non-conses are encountered.

copy-tree does not preserve circularities and the sharing of substructure.


 (setq object (list (cons 1 "one")
                    (cons 2 (list 'a 'b 'c))))
=>  ((1 . "one") (2 A B C))
 (setq object-too object) =>  ((1 . "one") (2 A B C))
 (setq copy-as-list (copy-list object))
 (setq copy-as-alist (copy-alist object))
 (setq copy-as-tree (copy-tree object))
 (eq object object-too) =>  true
 (eq copy-as-tree object) =>  false
 (eql copy-as-tree object) =>  false
 (equal copy-as-tree object) =>  true
 (setf (first (cdr (second object))) "a"
       (car (second object)) "two"
       (car object) '(one . 1)) =>  (ONE . 1)
 object =>  ((ONE . 1) ("two" "a" B C))
 object-too =>  ((ONE . 1) ("two" "a" B C))
 copy-as-list =>  ((1 . "one") ("two" "a" B C))
 copy-as-alist =>  ((1 . "one") (2 "a" B C))
 copy-as-tree =>  ((1 . "one") (2 A B C)) 

Side Effects: None.

Affected By: None.

Exceptional Situations: None.

See Also:


Notes: None.

The following X3J13 cleanup issue, not part of the specification, applies to this section:

[Starting Points][Contents][Index][Symbols][Glossary][Issues]
Copyright 1996, The Harlequin Group Limited. All Rights Reserved.