Re: Equality of foreign objects
- From: Scott Burson <fset.slb@xxxxxxxxx>
- Date: Thu, 15 Oct 2009 22:49:49 -0700 (PDT)
On Oct 15, 8:24 pm, D Herring <dherr...@xxxxxxxxxxxxxxxxxxx> wrote:
Scott Burson wrote:
On Oct 14, 3:25 pm, Pascal Costanza <p...@xxxxxxxxx> wrote:
There is no generic equivalence predicate (in the CLOS sense) in Common
Lisp that can be extended for user-defined types, and there are good
reasons for that. Other languages that pretend to provide such generic
equivalence predicates get them wrong most of the time. The issues are
very subtle and very hard to solve.
No, they're really not. The correct rule is very simple: for
(mutable) object types, equality is identity; for (immutable) value
types, equality is by type-and-content (e.g. two sequence values are
equal iff they are of the same size and their elements are pairwise
equal). The little-known language Refine, which I used for years,
does things this way and it works great.
On the other hand, equality is not an intrinsic property; it requires
a well-defined metric. The number 1 is not equal to the number 5,
except modulo 2 or 4, or ...
Your rule is a good one, but it is just one rule more equal than others.
I think it's more than that. Equality is supposed to be the finest
possible equivalence relation. The fact that there exist coarser
equivalence relations that might be of use to someone is irrelevant.
This is why it really is wrong to compare (mutable) objects by type-
and-content, despite that lots of languages do it, and even FSet is
forced to go along in some common cases. It is always possible to
tell two mutable objects apart, if they really are distinct, by
modifying one and seeing that the other isn't affected. So type-and-
content comparison can never provide the finest possible equivalence
relation.
-- Scott
.
- Follow-Ups:
- Re: Equality of foreign objects
- From: Alessio Stalla
- Re: Equality of foreign objects
- References:
- Equality of foreign objects
- From: Alessio Stalla
- Re: Equality of foreign objects
- From: Pascal Costanza
- Re: Equality of foreign objects
- From: Scott Burson
- Re: Equality of foreign objects
- From: D Herring
- Equality of foreign objects
- Prev by Date: Re: DEFSTRUCT and lexical environment
- Next by Date: Which is better? Imago or ch-image
- Previous by thread: Re: Equality of foreign objects
- Next by thread: Re: Equality of foreign objects
- Index(es):
Relevant Pages
|