Eric Wilhelm asked me to chime in here. is_deeply() is about checking that two structures contain the same values. This is different from checking that they're the same *things*, that they are in fact the same object or reference.
You need both. Reading eqv() it seems that yes, it is doing like is_deeply() does and just cares about the values. So yes, by my reading Patrick is right, [1,2,3] eqv [1,2,3] should be true. S03 says: "the eqv operator tests whether the canonical representation of both subvalues would be identical" and that's really useful. One thing that isn't addressed is what happens to objects? For example, the following passes with is_deeply()... my $obj = bless [1,2,3], "Foo"; is_deeply( $obj, [1,2,3] ); but that's just because it's convenient for testing and the Perl 5 "objects are just references" thing. I understand that objects can define their own eqv() functions, but a good default would seem to be that if one is a subclass of the other, that's ok. And here's the annotated spec test. # Reference types { my @a = (1,2,3); my @b = (1,2,3); ok ([EMAIL PROTECTED] eqv [EMAIL PROTECTED]), "eqv on array references (1)"; ok ([EMAIL PROTECTED] eqv [EMAIL PROTECTED]), "eqv on array references (2)"; #?pugs todo 'bug' ok !([EMAIL PROTECTED] eqv [EMAIL PROTECTED]), "eqv on array references (3)"; # wrong } { my $a = \3; my $b = \3; ok ($a eqv $a), "eqv on scalar references (1-1)"; ok ($b eqv $b), "eqv on scalar references (1-2)"; #?pugs todo 'bug' ok !($a eqv $b), "eqv on scalar references (1-3)"; # wrong } { my $a = { 3 }; my $b = { 3 }; ok ($a eqv $a), "eqv on sub references (1-1)"; ok ($b eqv $b), "eqv on sub references (1-2)"; ok !($a eqv $b), "eqv on sub references (1-3)"; # wrong } { ok (&say eqv &say), "eqv on sub references (2-1)"; ok (&map eqv &map), "eqv on sub references (2-2)"; ok !(&say eqv &map), "eqv on sub references (2-3)"; } { my $num = 3; my $a = \$num; my $b = \$num; ok ($a eqv $a), "eqv on scalar references (2-1)"; ok ($b eqv $b), "eqv on scalar references (2-2)"; ok ($a eqv $b), "eqv on scalar references (2-3)"; } { ok !([1,2,3] eqv [4,5,6]), "eqv on anonymous array references (1)"; #?pugs 2 todo 'bug' wrong ok !([1,2,3] eqv [1,2,3]), "eqv on anonymous array references (2)"; wrong ok !([] eqv []), "eqv on anonymous array references (3)"; } { ok !({a => 1} eqv {a => 2}), "eqv on anonymous hash references (1)"; wrong ok !({a => 1} eqv {a => 1}), "eqv on anonymous hash references (2)"; } { ok !(\3 eqv \4), "eqv on anonymous scalar references (1)"; #?pugs 2 todo 'bug' wrong ok !(\3 eqv \3), "eqv on anonymous scalar references (2)"; wrong ok !(\undef eqv \undef), "eqv on anonymous scalar references (3)"; } # Chained eqv (not specced, but obvious) { ok (3 eqv 3 eqv 3), "chained eqv (1)"; ok !(3 eqv 3 eqv 4), "chained eqv (2)"; } # Subparam binding doesn't affect eqv test { my $foo; my $test = -> $arg { $foo eqv $arg }; $foo = 3; ok $test($foo), "subparam binding doesn't affect eqv (1)"; ok $test(3), "subparam binding doesn't affect eqv (2)"; ok !$test(4), "subparam binding doesn't affect eqv (3)"; my $bar = 4; ok !$test($bar), "subparam binding doesn't affect eqv (4)"; } { is(1 eqv 1, Bool::True, 'eqv returns Bool::True when true'); is(0 eqv 1, Bool::False, 'eqv returns Bool::False when false'); } Patrick R. Michaud wrote: > On Sun, Sep 14, 2008 at 03:08:57PM +0200, Carl Mäsak wrote: >> Recently, in November, we've had reason to clone the Rakudo Test.pm >> and add an implementation (viklund++) of is_deeply, for testing >> whether two arrays, pairs or hashes are deeply -- recursively -- >> equivalent. The method does what you'd think it does, checks the types >> of its parameters and recurses as necessary. >> >> With the rich set of equality testing operators in Perl 6... >> >> <http://www.dlugosz.com/Perl6/web/eqv.html> >> <http://perlcabal.org/syn/S03.html#Comparison_semantics> >> >> ...and given constructs like [+] and <+>, it's actually a bit >> surprising to me that testing whether [1, [2, 3]] and [1, [2, 4]] are >> the deeply equivalent isn't more easily expressed than it is. (Or >> maybe it is easy with current constructs, and I missed it? Can't rule >> that out.) >> >> Couldn't an adverb to one or more of the existing equality operators >> do this nicely? Something like this: >> >> say [1, [2, 3]] eqv [1, [2, 4]] :deeply; > > Doesn't infix:<eqv> already somewhat imply the "is deeply" semantics, > at least for arrays and hashes? > > As far as current implementation status is concerned, I think > that the t/spec tests have this wrong in many cases -- they seem > to assume that infix:<eqv> tests object identity for equivalence > instead of comparing values. For example, t/spec/S29-any/eqv.t has: > > ok !([1,2,3] eqv [4,5,6]), "eqv on anonymous array references (1)"; > #?pugs 2 todo 'bug' > ok !([1,2,3] eqv [1,2,3]), "eqv on anonymous array references (2)"; > ok !([] eqv []), "eqv on anonymous array references (3)"; > > I think that the last two tests are incorrect, and that > [1,2,3] eqv [1,2,3] should give a True result. -- 39. Not allowed to ask for the day off due to religious purposes, on the basis that the world is going to end, more than once. -- The 213 Things Skippy Is No Longer Allowed To Do In The U.S. Army http://skippyslist.com/list/