Over at #perl6 we had a short discussion on =:=, ===, and ~~, mostly raised by
ajs's discussion on Str items and ===.

After a brief discussion we managed to formulate several questions that we feel
are slightly to totally unresolved.

1. what is .id on references? Is it related to the memory slot, like refaddr()
in Perl 5?

2. is .id *always* a low level type representation of the object's value? It's
specced that low level typed items have the same ID when they have the same
value. What about complex types?

3. Are these descriptions of the operators correct?

        ~~ matches the left side to a description on the right side

        =:= makes sure the objects are actually the same single object (if $x 
=:= $y
        and you change $x.<foo> then $y.<foo> was also changed... is
        this .id on refs?) Is =:= really eq .id? or more like
        variable($x).id eq variable($y).id?

        === makes sure that the values are equivalent ( @foo = ( 1, 2, 3 ); 
@bar = ( 1,
        2, 3); @foo === @bar currently works like that, but @foo = ( [ 1, 2 ], 
3 );
        @bar = ( [ 1, 2 ], 3 ); @foo === @bar does not (in pugs). This is not 
useful
        because we already have this return false with =:=).

If they are not correct, why is there an overlap between =:=? Why is it hard to
deeply compare values in 2006 without using e.g. Data::Compare?

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?

5. is there room for a new opperator?

        =::= makes sure the memory slot  is the same (might be different
        for simple values). refaddr($x) == refaddr($y) in Perl 5

        =:= makes sure that .ids are the same, and is useful if the .id
        method is meaningful for an object. A bit like Test::More::is(
        $x, $y ) but without the diagnosis in Perl 5, or abusing eq if
        the object doesn't overload stringification.

        === makes sure the values are the same even if they are
        copies/clones/whatever. Data::Compare in Perl 5. A bit like what
        people overload == for in Perl 5 right now (which confuses
        "numerical" equality with "true" equality, so we want to phase
        that out).

        ~~ makes sure the value on the right side describes the value on
        the left side. Reminiscient of Test::Deep::cmp_deeply, with all
        the various matching magic.

Thanks,

[1] It could, of course, be just =:= && === inside, and it could optimize
arrays to check length first, and it could cache checksums and it could do
whatever - please don't bring this up as a performance issue, it is one of
correctness and ergonomics that must be resolved first.

-- 
  Yuval Kogman <[EMAIL PROTECTED]>
http://nothingmuch.woobling.org  0xEBD27418

Attachment: pgpVx2Q88D1JG.pgp
Description: PGP signature

Reply via email to