Contents    Page-10    Prev    Next    Page+10    Index   

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:


(defun equal (pat inp)
  (if (consp pat)          ; interior node?
      (and (consp inp)
           (equal (first pat) (first inp))
           (equal (rest pat) (rest inp)))
      (eql pat inp) ) )    ; leaf node


>(equal '(+ a (* b c)) '(+ a (* b c)))

T