Skip to content

Commit

Permalink
Explain that eqv doesn't work for arbitrary objects
Browse files Browse the repository at this point in the history
And add a note about how to implement `eqv` if one needs this behaviour.
This should address the issue raised in #81.
  • Loading branch information
Paul Cochrane committed Jul 25, 2015
1 parent ec719b8 commit 4c57c15
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/Language/operators.pod
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,24 @@ the same, i.e. from the same type and (recursively) contain the same values.
say 1 eqv 2; # False
say 1 eqv 1.0; # False
For arbitrary objects this is not possible with the default C<eqv> operator.
E.g., C<eqv> will not consider two instances of the same object as being
structurally equivalent:
class A {
has $.a;
}
say A.new(a => 5) eqv A.new(a => 5); #=> False
To get C<eqv> semantics for objects of this class, one would need to
implement an appropriate infix C<eqv> operator:
class A {
has $.a;
}
multi infix:<eqv>(A $l, A $r) { $l.a eqv $r.a }
say A.new(a => 5) eqv A.new(a => 5); #=> True
=head2 infix C«===»
proto sub infix:<===>(Any, Any) returns Bool:D is assoc<chain>
Expand Down Expand Up @@ -1367,3 +1385,5 @@ Returns the first defined argument, or else the last argument.
Short-circuits.
=end pod

# vim: expandtab shiftwidth=4 ft=perl6

0 comments on commit 4c57c15

Please sign in to comment.