copy_tree

copy_tree — copies the entire tree structure and elements of a list.

Syntax

copy_tree (s_exp)

		

Arguments

s_exp

Any Gamma or Lisp expression.

Returns

A copy of the entire tree structure and elements of the argument, if it is a list. Otherwise, the argument.

Description

This function makes a recursive copy of the entire tree structure of the argument if the argument is a list, otherwise it simply returns the argument. This produces a new list which is equal to the previous list, and whose elements are equal, but not eq. That is, the elements are all copied down to the level of the non-list leaves. They are equal to the original elements, but they are different elements. Thus they are equal but not eq.

Example

Gamma> a = list(1,list(2,3,list(4),5));
(1 (2 3 (4) 5))
Gamma> b = copy_tree(a);
(1 (2 3 (4) 5))
Gamma> cadr(a);
(2 3 (4) 5)
Gamma> equal(cadr(a),cadr(b));
t
Gamma> eq(cadr(a),cadr(b));
nil
Gamma> 
		

See Also

copy, eq, equal