Skip to content

Commit 4c57c15

Browse files
committed
Explain that eqv doesn't work for arbitrary objects
And add a note about how to implement `eqv` if one needs this behaviour. This should address the issue raised in #81.
1 parent ec719b8 commit 4c57c15

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lib/Language/operators.pod

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,24 @@ the same, i.e. from the same type and (recursively) contain the same values.
949949
say 1 eqv 2; # False
950950
say 1 eqv 1.0; # False
951951
952+
For arbitrary objects this is not possible with the default C<eqv> operator.
953+
E.g., C<eqv> will not consider two instances of the same object as being
954+
structurally equivalent:
955+
956+
class A {
957+
has $.a;
958+
}
959+
say A.new(a => 5) eqv A.new(a => 5); #=> False
960+
961+
To get C<eqv> semantics for objects of this class, one would need to
962+
implement an appropriate infix C<eqv> operator:
963+
964+
class A {
965+
has $.a;
966+
}
967+
multi infix:<eqv>(A $l, A $r) { $l.a eqv $r.a }
968+
say A.new(a => 5) eqv A.new(a => 5); #=> True
969+
952970
=head2 infix C«===»
953971
954972
proto sub infix:<===>(Any, Any) returns Bool:D is assoc<chain>
@@ -1367,3 +1385,5 @@ Returns the first defined argument, or else the last argument.
13671385
Short-circuits.
13681386
13691387
=end pod
1388+
1389+
# vim: expandtab shiftwidth=4 ft=perl6

0 commit comments

Comments
 (0)