[R6RS] R6RS records: record equality

Marc Feeley feeley
Fri Aug 26 14:48:45 EDT 2005

[Sorry for the long silence but I had to deal with a hard disk crash  
and other problems when I returned from vacation.  I will separate my  
comments in different threads... more to follow.]

The specification indicates that two records are equal? iff they are
eq? (except if they represent builtin types like pairs, vectors, etc).
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?.  Here is a rationale:

1) It provides more functionality than eq?.  If you want to check if
    two records are identical, use eq?.  If you want to check that
    their content is the same, use equal?.  There is no advantage in
    having eq? and equal? behave the same.

2) For the predefined structured types (pairs, vectors, and strings),
    equal? checks the content of the objects.  I find it quite
    intuitive to define equal? on records to also check for equality of
    the content.  Moreover, I expect most implementations of the record
    system to provide an external textual representation of the record
    that contains the content of each field.  It will be surprising for
    novices when two objects that print the same are not equal? given
    that R5RS says: "A rule of thumb is that objects are generally
    equal? if they print the same."

3) When implementing a registry it is convenient to use composite
    objects as the key of a hash table.  A concrete example is in a
    distributed programming system we have built on top of Gambit
    (called Termite).  A registry of objects is maintained on each node
    of the distributed system to remember which local objects have been
    communicated to other nodes.  The registry maps the "global
    identifier" of an object to the local representative of that
    object.  When an object is communicated from a node A to a node B
    for the first time, a new global identifier is generated and added
    to A's registry.  The global identifier is then communicated to B
    which performs a lookup in its registry.  If B does not have a
    local representative for that object, one is created and added to
    B's registry under that global identifier.  Note that the
    registry could be an association list managed with assoc, or a
    hash-table which compares keys with equal? (such as SRFI-69).
    We represent these global identifiers using records with two
    fields: the IP-address of the node, and a "name", a string
    useful for identifying sub-nodes.  The IP-address is itself
    a record with an IPv4/IPv6 address and a port number.  Sure we
    could have used lists or vectors to represent these global
    identifiers, but that would have been less elegant and
    caused maintenance problems (more opaque code, conversion
    functions, etc).

For these reasons I prefer a recursive definition for equal? on
records.  We may however decide that for opaque records, equal? = eq?.

Aside from that I don't understand the rationale for

   (eqv? r1 r2)  not implying  (eq? r1 r2)

What's the practical use for this?


More information about the R6RS mailing list