At page 202 in the book Pharo by Exmaple, it says:

"A difficult error to spot is when you redefine = but not hash. The symptoms
are that you will lose elements that you put in sets or other strange
behaviour. ..."


I have come up of an idea that can blow this away.


HashProof is a trait that guarantees that #hash and #= are defined
correctly.

If you file in this  http://forum.world.st/file/n3809543/HashProof.st
HashProof.st ,
You will see HashProofTrait computes #= and #hash by using an array answered
by the trait user by sending message #gettersForEquality.

HashProofUser uses HashProofTrait. 

Try example below,

u := HashProofUser new.
u x:1.
u y:2.
u z:3.
v := HashProofUser new.
v x:1.
v y:2.
v z:3.

u = v.


User of the HashProofTrait is meets an error undefined message
#gettersForEquality, when it was first sent #= or #hash. Therefore, it is
very clear what he has to do to make #= and #hash work flawlessly.


HwaJong Oh

--
View this message in context: 
http://forum.world.st/HashProof-tp3809543p3809543.html
Sent from the Pharo Smalltalk mailing list archive at Nabble.com.

Reply via email to