User Tools


Function COPY-TREE

Syntax

  • copy-tree treenew-tree

Arguments and Values

Description

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.

Examples

(defparameter *object* (list (cons 1 "one") (cons 2 (list 'a 'b 'c))

*OBJECT*

(defparameter *object-too* *object*)

*OBJECT-TOO*

(defparameter *copy-as-list* (copy-list *object*))

*COPY-AS-LIST*

(defparameter *copy-as-alist* (copy-alist *object*))

*COPY-AS-ALIST*

(defparameter *copy-as-tree* (copy-tree *object*))

*COPY-AS-TREE*

(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

Example Implementation

To be done.

Notes

None.