At 5:36 PM +0300 7/13/06, Yuval Kogman wrote:
> User defined types can choose on their own whether to override === and/or .id or not, and they would use their own knowledge of their internal structures to do an appropriate
deep comparison. There is no need to try to generate some kind of unique numerical .id for arbitrarily complex objects.

That creates a mess - sometimes objects compare themselves based on
their value, and sometimes based on their containing slot. These are
very different semantics.

The idea here is that === is a test for deep-as-possible immutable equality. If the user-defined object is immutable, then === does a full deep compare. If the object is mutable, then === goes only as deep as can be guaranteed will never change, which is usually what =:= looks at and no further. There is no mess at all, the comparing by value is related to the immutability, and all objects of the same class would be the same in that respect. Incidentally, your Currency example would likely be an immutable type. -- Darren Duncan

Reply via email to