[R6RS] R6RS records: record equality

Michael Sperber sperber
Mon Aug 29 13:17:50 EDT 2005


Marc Feeley <feeley at iro.umontreal.ca> writes:

> Could you be more explicit.  I don't follow why you think this is a  
> bad idea.  Given that records can be tested with eq? if the user  
> wants to,

You mean EQV?, presumably.  EQ? doesn't do it.

> why is it necessary for equal? to behave the same, and
> counter-intuitively to what happens for pairs, vectors and strings?

R5RS has this:

> A rule of thumb is that objects are generally equal? if they print
> the same.

... and given that we've agreed not to address external
representations for the records at this point, and the common ways of
addressing them would still violate this rule, my intuition is pretty
much exactly what the SRFI says.  (Modulo the unboxing issue,
possibly, but there's a clear rationale for that.)

Any definition of the behavior of the R5RS equality predicates has
downsides in some contexts.  The Common Lisp folks have
chewed through this issue extensively here:

http://www.lisp.org/HyperSpec/Issues/iss143-writeup.html

The page contains a commentary paragraph:

    Object equality is not a concept for which there is a uniquely
    determined correct algorithm. The appropriateness of an equality
    predicate can be judged only in the context of the needs of some
    particular program. Although these functions take any type of
    argument and their names sound very generic, EQUAL and EQUALP are
    not appropriate for every application. Any decision to use or not
    use them should be determined by what they are documented to do
    rather than any abstract characterization of their function. If
    neither EQUAL nor EQUALP is found to be appropriate in a particular
    situation, programmers are encouraged to create another operator
    that is appropriate rather than blame EQUAL or EQUALP for ``doing
    the wrong thing.''

I agree with this paragraph.  Note that CL has an additional equality
predicate that does descend into structures/records, and I'd be
amenable to discussing adding *that* (albeit outside the SRFI).

In my experience, EQUALP is not the right thing in many cases, and
given its seductiveness, it often introduces a discontinuity into the
software development process: I'd use EQUALP until something deep
inside a tree structure required something different, and then I'd
have to

a) write my own equality predicate, which is, at that point, a lot of
   work all at once
b) find the inappropriate uses of EQUALP and eliminate them, which is
   a lot of work, and also unreliable and error-prone

An additional equality predicate, or more complex behavior of the
existing ones, would also make the situation even more confusing than
it arguably already is.

The whole problem could presumably be addressed in the context of some
larger data structure / container / whatever infrastructure, with a
dispatch mechanism and so on, but this seems too large a bite for R6RS
by quite a bit.  (The SRFI efforts in that direction haven't gotten
very far yet.)  Moreover, it's unclear that the records proposal and
EQUAL? are necessarily the right place to start with this; I
personally don't think so.

-- 
Cheers =8-} Mike
Friede, V?lkerverst?ndigung und ?berhaupt blabla


More information about the R6RS mailing list