On Wed, Jul 12, 2006 at 04:16:13PM -0400, Aaron Sherman wrote:
> On Wed, 2006-07-12 at 19:25 +0300, Yuval Kogman wrote:
> > 4. will we have a deep (possibly optimized[1]) equality operator, that
> > *will* return true for @foo = ( [ 1, 2 ], 3 ); @bar = ( [ 1, 2 ], 3 ); 
> > op(@foo, @bar)?
> > Is it going to be easy to make the newbies use that when they mean "it's the
> > same", like they currently expect == and eq to work on "simple" values?
> 
> Isn't that ~~?
> 
> Per S03:
> 
>         Array   Array     arrays are comparable    match if $_ »~~« $x
> 
> ~~ is really the all-purpose, bake-your-bread, clean-your-floors,
> wax-your-cat operator that you're looking for.

Granted, ~~ will return true in that case.  I think the main problem
is Yuval wants a guarantee that it will return true if and only if
the things on either side have the same deep structure and values.

Currently, ~~ will also return true for structures where this does
not hold.  For example:

    @a = ( [ 1, 2] , 3 );
    @b = ( sub { return 1 }, sub { return 1 } );
    @a ~~ @b;                           # true

Why is that true?  By the rules of hyper-operation, it turns into
this:

    [1,2] ~~ sub { return 1 }
    3 ~~ sub { return 1 }

which is true if these return true values:

    sub { return 1 }->([1,2])
    sub { return 1 }->(3)

Which they do.

So, smart-match fails as a "deep equality" operator precisely
because it's so smart.

-Scott
-- 
Jonathan Scott Duff
[EMAIL PROTECTED]

Reply via email to