On 7/2/05, Fergal Daly <[EMAIL PROTECTED]> wrote:
> Here's a way of looking at it that doesn't require you to consider
> what happens if you alter the structures.
>
> Let's say you have a Person class with a Name an Age and a House class
> with Owner and Resident.
>
> Now imagine there are 2 people who have the same name and age but are
> different people.
>
> my $p1 = Person->new(Name => "Fergal Daly", Age => 31);
> my $p2 = Person->new(Name => "Fergal Daly", Age => 31);
>
> They live in 2 houses but one of the owns both houses.
> my $h1 = House->new(Owner => $p1, Resident => $p1);
> my $h2 = House->new(Owner => $p1, Resident => $p2);
>
> The houses look identical if you only consider values however Yves
> wants to also consider identities. $h1 is owner-occupied $h2 is
> presumably being rented.
>
> Here's what CalculateRent could look like:
>
> sub CalculateRent
> {
> my $house = shift;
> if ($house->Owner eq $house->Resident)
> {
> return 0;
> }
> else
> {
> return ValueHouse($house) / 360;
> }
> }
>
> so curently
>
> is_deeply($h1, $h2)
>
> passes but
>
> CalculateRent($h1) == CalculateRent($h2)
>
> fails so there it definitely something unequal about $h1 and $h2.
> There is a stronger form of equality that could be tested which would
> guarantee that if
>
> is_really_deep($h1, $h2)
>
> passes then
>
> AnyFunction($h1) == AnyFunction($h2)
>
> would also pass (assuming there are no conflicting side effects and
> assuming nothing looks directly at reference addresses - apart from
> debugging, there's no reason to ever do this anyway),
Yes this is an excellent explanation. A simplification futher would be:
You are playing on some TV gameshow. You've won the big prize: a
house. Now the thing is that the presenter gives you a choice of two
envelopes. Both contain two house addresses. However one contains the
same address twice and the other contains two seperate addresses.
The folks that argue that [$x,$x] is no different from [$x,$y] would
say that it doesnt matter which envelope you choose as there is no
difference. Those of use saying that [$x,$x] is different from [$x,$y]
would suggest the opposite.
Which envelope would you choose?
:-)
yves
--
perl -Mre=debug -e "/just|another|perl|hacker/"