Skip to content

Commit

Permalink
Elaborate a bit about ===
Browse files Browse the repository at this point in the history
- show that it disregards containers
- put in link to ValueObjAt to create custom .WHICH methods
  • Loading branch information
lizmat committed Jul 17, 2018
1 parent ea2a05b commit 5e73790
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions doc/Language/operators.pod6
Expand Up @@ -1762,7 +1762,8 @@ implement an appropriate infix C<eqv> operator:
sub infix:<===>(Any, Any)
X<Value identity operator>. Returns C<True> if both arguments are the same object.
X<Value identity operator>. Returns C<True> if both arguments are the same
object, disregarding any containerization.
my class A { };
my $a = A.new;
Expand All @@ -1775,11 +1776,18 @@ For value types, C<===> behaves like C<eqv>:
say 'a' === 'a'; # OUTPUT: «True␤»
say 'a' === 'b'; # OUTPUT: «False␤»
my $b = 'a';
say $b === 'a'; # OUTPUT: «True␤»
# different types
say 1 === 1.0; # OUTPUT: «False␤»
C<===> uses the L<WHICH|/routine/WHICH> method to obtain the object identity, so all value
types must override method C<WHICH>.
C<===> uses the L<WHICH|/routine/WHICH> method to obtain the object identity.
If you want to create a class that should act as a value type, then that
class must create an instance method C<WHICH>, that should return a
L<CValueObjAt|type/ValueObjAt> object that won't change for the lifetime of
the object.
=head2 infix C«=:=»
Expand Down

0 comments on commit 5e73790

Please sign in to comment.