Tree Equality
It often is necessary to test whether two trees are equal, even though they are in different memory locations. We will say two trees are equal if:
(defn equal [x y] (if (cons? x) (and (cons? y) (equal (first x) (first y)) (equal (rest x) (rest y))) (= x y) ))
>(equal '(+ a (* b c)) '(+ a (* b c))) true
Some say that two trees are equal if they print the same.
Note that this function treats a cons as a binary first-rest tree rather than as a lhs-rhs tree.