chickadee » genequal » generalized-equal?

generalized-equal? obj1 obj2 #!rest comparator-listprocedure

A comparator is a procedure that is given two arguments to compare. It returns #t if its arguments are to be considered equal, #f if they are to be considered unequal, and any other value if it cannot decide. The third argument passed to a comparator is a list of comparators to be used in recursive calls to generalized-equal?.

First, each element of comparator-list is invoked on obj1 and obj2, passing comparator-list as its third argument. If the comparator returns #t or #f, that is the result.

If all comparators in the list have been invoked without a #t or #f result, then generalized-equal? determines if both obj1 and obj2 are pairs, strings, vectors, u8vectors, hash tables with the same test function, or SRFI-99 records of the same type. (It cannot introspect on SRFI-9 or Chicken-native records.) If they are not, then generalized-equal? returns what eqv? returns on obj1 and obj2.

Otherwise, if the containers have different numbers of elements, the result is #f. Otherwise, generalized-equal? invokes itself recursively on each corresponding element of the containers, passing itself the same comparators. If a recursive call returns #f, that is the result; if all recursive calls return #t, that is the result.