develooper Front page | perl.perl6.language | Postings from July 2006

Re: ===, =:=, ~~, eq and == revisited (blame ajs!)

Thread Previous | Thread Next
From:
Darren Duncan
Date:
July 13, 2006 21:15
Subject:
Re: ===, =:=, ~~, eq and == revisited (blame ajs!)
Message ID:
p06230900c0dcc948b358@[192.168.1.101]
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

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About