You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In signatures.rakudoc, remove mention of nonexistent trait is optional, and change =:= to === (#4645)
* In signatures.rakudoc, remove mention of nonexistent trait `is optional`
Trying to use the trait "is optional" in a function signature throws error "Can't use unknown trait" (in all of v6.c, v6.d and v6.e.PREVIEW).
* Update signatures.rakudoc: Change `=:=` to `===` and adapt text
The change of `=:=` to `===` is necessary in the second example, because `=:=` would just always produce False there.
From the explanation above the first example, `===` also seems like the better choice there (even though `=:=` also works as intended).
Namely, it is `===` which calls the `.WHICH` method. I've added this as a remark to the text, and have rearranged the text slightly.
* Update signatures.rakudoc: whitespace
Copy file name to clipboardExpand all lines: doc/Language/signatures.rakudoc
+6-8Lines changed: 6 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -1000,16 +1000,17 @@ Table showing checks of whether an argument was passed for a given parameter:
1000
1000
1001
1001
¹ A suitable default is an Object that has a distinct identity, as may be checked by the L<C<WHICH>|https://docs.raku.org/type/Mu#method_WHICH> method.
1002
1002
1003
-
A parameter with a default is always I<optional>, so there is no need to mark it with a C<?> or the C<is optional> trait.
1003
+
A parameter with a default is always I<optional>, so there is no need to mark it with a C<?>.
1004
1004
1005
-
Then you can use the C<=:=> L<container identity operator|https://docs.raku.org/language/operators#infix_=:=> in the body of the routine to check
1006
-
whether this exact default was bound to the parameter.
1005
+
Then you can use the C<===> L<value identity operator|https://docs.raku.org/language/operators#infix_===> in the body of the routine to check
1006
+
whether this exact default object was bound to the parameter. These examples use names like C<PositionalAt> to reflect that the C<.WHICH> test
1007
+
invoked by C<===> returns an object of type L<C<ObjAt>|/type/ObjAt>.
1007
1008
1008
1009
Example with a positional parameter:
1009
1010
=begin code
1010
1011
my constant PositionalAt = Positional.new;
1011
1012
1012
-
sub a (@list = PositionalAt) { say @list =:= PositionalAt }
1013
+
sub a (@list = PositionalAt) { say @list === PositionalAt } # here, one can also use =:=, the container indentity operator
1013
1014
a; # OUTPUT: «True»
1014
1015
a [1, 2, 3]; # OUTPUT: «False»
1015
1016
=end code
@@ -1018,7 +1019,7 @@ Example with some scalar parameters:
1018
1019
=begin code
1019
1020
my constant AnyAt = Any.new;
1020
1021
1021
-
sub b ($x=AnyAt, :$y=AnyAt) { say $x =:= AnyAt; say $y =:= AnyAt }
1022
+
sub b ($x=AnyAt, :$y=AnyAt) { say $x === AnyAt; say $y === AnyAt } # here, =:= would always produce False
1022
1023
b 1; # OUTPUT: «FalseTrue»
1023
1024
b 1, :2y; # OUTPUT: «FalseFalse»
1024
1025
=end code
@@ -1035,9 +1036,6 @@ c (Int); #Undefined
1035
1036
c 42; #Defined
1036
1037
=end code
1037
1038
1038
-
The examples use names like C<PositionalAt> to reflect that the C<.WHICH> test returns an object of type L<C<ObjAt>|/type/ObjAt>,
1039
-
you are free to make up you own names.
1040
-
1041
1039
=head1 Dynamic variables
1042
1040
1043
1041
L<Dynamic variables|/language/variables#The_*_twigil> are allowed in signatures
0 commit comments