This site is a static rendering of the Trac instance that was used by R7RS-WG1 for its work on R7RS-small (PDF), which was ratified in 2013. For more information, see Home. For a version of this page that may be more recent, see GeneralizedEqualCowan in WG2's repo for R7RS-large.

Generalized­Equal­Cowan

cowan
2013-05-22 22:32:38
14history
source

Generalized equal? predicate

(generalized-equal? obj1 obj2 . comparator-list)

Compares obj1 and obj2 for equality. 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 the symbol pass if it cannot decide. It is an error for a comparator to return anything else. The third argument passed to a comparator is comparator-list, 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 comparator-list have been invoked with a pass result, then generalized-equal? behaves as if it had been invoked on the comparators list-comparator, string-comparator, vector-comparator, and bytevector-comparator defined below, plus additional implementation-defined comparators if any. If all of these return pass, then generalized-equal? returns what eqv? returns.

(make-atomic-comparator type-predicate compare-predicate)

Returns a comparator that invokes type-predicate on its first and its second arguments. If they both return #t, then they are assumed to be of the same type, and compare-predicate is invoked on the first and second arguments together. If the result is #t or #f, then the comparator returns #t or #f respectively. If they are not of the same type, a third value is returned. The resulting comparator always ignores its third argument.

Standard comparators

(numeric-comparator obj1 obj2 comparators-list)

A comparator that returns #t if obj1 and obj2 are numbers that are equal in the sense of =, #f if they are numbers that are not equal in the sense of =, and pass otherwise. The comparators-list argument is ignored.

(char-ci-comparator obj1 obj2 comparators-list)

A comparator that returns #t if obj1 and obj2 are characters that are equal in the sense of char-ci=?, #f if they are characters that are not equal in the sense of char-ci=?, and pass otherwise. The comparators-list argument is ignored.

(list-comparator obj1 obj2 comparators-list)

A comparator that returns #t if obj1 and obj2 are lists of the same length whose elements are equal in the sense of generalized-equal? when passed comparators-list, #f if they are lists that are not equal in that sense, and pass otherwise. The comparators-list argument is ignored.

(string-comparator obj1 obj2 comparators-list)

A comparator that returns #t if obj1 and obj2 are strings that are equal in the sense of string=?, #f if they are strings that are not equal in the sense of string=?, and pass otherwise. The comparators-list argument is ignored.

(string-ci-comparator obj1 obj2 comparators-list)

A comparator that returns #t if obj1 and obj2 are strings that are equal in the sense of string-ci=?, #f if they are strings that are not equal in the sense of string-ci=?, and pass otherwise. The comparators-list argument is ignored.

(vector-comparator obj1 obj2 comparators-list)

A comparator that returns #t if obj1 and obj2 are vectors of the same length whose elements are equal in the sense of generalized-equal? when passed comparators-list, #f if they are vectors that are not equal in that sense, and pass otherwise. The comparators-list argument is ignored.

(bytevector-comparator obj1 obj2 comparators-list)

A comparator that returns #t if obj1 and obj2 are bytevectors of the same length whose elements are equal in the sense of generalized-equal? when passed comparators-list, #f if they are bytevectors that are not equal in that sense, and pass otherwise. The comparators-list argument is ignored.

When used by an implementation that doesn't provide bytevectors, this procedure always returns pass.