Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view


HwaJong Oh
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 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