Michael G Schwern <[EMAIL PROTECTED]> writes:

> On Fri, Jul 01, 2005 at 07:11:26AM +0000, Smylers wrote:
>> > The question you have to ask yourself is why should a reference be
>> > treated different from any other value? It is a VALUE.
>> 
>> Except it isn't.  Or at least, not all the time: it depends how you wish
>> to look at it.  If you just consider a reference to be a value
>> (effectively a pointer, a memory address) then you aren't examining a
>> data structure _deeply_; you're just doing a _shallow_ comparision of it
>> as a reference.
>
> I think this hits the nail on the head.  References are treated differently
> because we don't look at the reference we look at the data that reference
> points to.  is_deeply() does this fairly consistently ignoring blessing,
> ties and overloading.
>
> Under the proposed logic, this test fails:
>
>   my $a = [];
>   my $b = [];
>   my $c = [];
>
>   my $x = [$a, $a];
>   my $y = [$b, $c];
>
>   is_deeply($x, $y);
>
> because $x and $y can be altered in exactly the same way yet come out
> differently.
>
>   $x->[0][0] = 1;  # [[1],[1]]
>   $y->[0][0] = 1;  # [[1],[]]
>
> There's plenty of other cases where this can happen.  If $x is tied.  If $x
> is a string overloaded object.  If $x is an object.  These can lead to 
> situations where the same operation is applied to both structures yet 
> results in different structures.  But we ignore this because is_deeply()
> has to draw a line between internal and external information somewhere.
> Its drawn at the reference value.
>
> is_deeply() is not about exact equivalence.  Its about making a best fit
> function for the most common uses.  I think most people expect [$a, $a] and
> [$b,$c] to come out equal.

I've always thought of C<is_deeply> as being about the 'shape' of a data
structure. When you think of things in this way, then it seems obvious that
given

    $a = [], $b = [], $c = []

then [$a, $a] and [$b, $c] have substantially different shapes.

Reply via email to