Alexey Radul scripsit:
> I am of the opinion that Henry Baker [1] was right about object identity
> -- the only true identity comparison compares immutable (portions of)
> objects structurally, and mutable ones by location.
I agree entirely. Unfortunately, history places its own demands
on what a standard Scheme can provide.
> The existence of equal? is justified by the fact that, though Scheme's
> compound objects are all mutable, many of them (notably pairs and
> vectors) are often used immutably, so structural comparison is an
> extremely valuable operation.
In addition, if two ordered mutable containers contingently contain the
same values at a particular moment in their evolution, equal? can test
for that situation as well. However, equal? is limited in what it can
handle by the weight of tradition: it descends into pairs, vectors,
and strings (to which R6RS and R7RS add bytevectors), but reports
the same as eqv? for all other objects, including user-defined or
implementation-specified ones.
I am therefore proposing generalized-equal? for R7RS-large, which
accepts two objects and an arbitrary number of comparators, which are
procedures that are called in sequence, returning #t if their arguments
are generalized-equal?, #f if they are not, and 'pass if the procedure
cannot tell. Each comparator is also passed the full current list of
comparators, to allow it to invoke generalized-equal? recursively.
By using comparators for numeric, char-ci, string-ci, and hashtable
equality, for example, we get the equivalent of CL equalp.
> But why does Scheme have eq? ? The only possible justification for
> eq? is that sometimes (e.g., bignums) structural comparison is too
> expensive, so the programmer is willing to sacrifice accurate
> identification of immutable objects in order to guarantee efficient
> execution.
Just so.
> As an editorial suggestion, this can be implemented
> without duplication of words by defining that eqv? on procedures is
> required to return #t if eq? does, and spelling out the minimum
> requirements of procedure identity in the specification of eq?.
Editorially, Scheme has always defined eq? by its difference from eqv?
rather than vice versa.
To say that Bilbo's breath was taken away is no description at all. There are
no words left to express his staggerment, since Men changed the language that
they learned of elves in the days when all the world was wonderful. --The Hobbit