[R6RS] R6RS records: record equality

William D Clinger will
Mon Aug 29 14:00:36 EDT 2005

After you've been in the institution long enough, they give
you a funny hat that says "institutional memory".  Putting
on that hat, I'd like to review some of the rationale for
some of the differences between the eqv? and eq? procedures,
and then muse about how they should behave with records.

Two values are eqv? if and only if they are interchangeable
for most practical purposes.  The eq? procedure is a faster
alternative that weakens the "if and only if" to "only if".
For some cases, however, eqv? and eq? are guaranteed to behave
the same.  These cases fall into three groups:

1.  Certain "atomic" values that are tested for equality so
frequently that programmers have good reason to want to use
the faster eq? test with them: symbols, booleans, the empty

2.  Mutable structures, for which eq? returns true if and
only if mutating one argument will mutate the other: pairs
and non-empty vectors.

3.  Procedures, for which the behavior of eqv? and eq? is
more of a political compromise than a rational design.

To extend this to records, we could choose between

A.  Requiring eqv? and eq? to behave the same on mutable
records, but not requiring them to behave the same on
immutable records or on immutable record type descriptors.
Group 2 above, and the fact that eqv? is not required to
behave like eq? on empty vectors, would be the precedent.

B.  Some political compromise, unconstrained by rational
design.  Group 3 above would be the precedent.

C.  Neither of the above, without precedent.

Marc wrote:
> I object to the "equal? iff eq?" because it limits the use of records.
> I would prefer a recursive definition where (equal? r1 r2) is true iff
> r1 and r2 are of the same record type, and for each field, the contents
> of that field in r1 and r2 are equal?.

IMO, the recursive definition of equal? for records is not
very useful because it makes equal? inefficient on records
(if equal? is required to terminate) or it makes equal?
nonterminating on non-records.  Programmers will not often
use an equality predicate that is known to be efficient or
(even worse) isn't guaranteed to terminate.

That's why I favor equal? iff eqv? (not eq?) for records.

> Moreover I don't see why the same type descriptor (in the sense of
> eq?) must be returned every time since there are no mutation
> operations on type descriptors.

I agree with this objection.  The records SRFI should say that
the same type descriptor (in the sense of eqv?) must be returned
every time, but eqv? should not imply eq? here.


More information about the R6RS mailing list