Skip to content

Commit 7e71c5a

Browse files
authored
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
1 parent d5363c1 commit 7e71c5a

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

doc/Language/signatures.rakudoc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,16 +1000,17 @@ Table showing checks of whether an argument was passed for a given parameter:
10001000

10011001
¹ 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.
10021002

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<?>.
10041004

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>.
10071008

10081009
Example with a positional parameter:
10091010
=begin code
10101011
my constant PositionalAt = Positional.new;
10111012

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
10131014
a; # OUTPUT: «True␤»
10141015
a [1, 2, 3]; # OUTPUT: «False␤»
10151016
=end code
@@ -1018,7 +1019,7 @@ Example with some scalar parameters:
10181019
=begin code
10191020
my constant AnyAt = Any.new;
10201021

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
10221023
b 1; # OUTPUT: «False␤True␤»
10231024
b 1, :2y; # OUTPUT: «False␤False␤»
10241025
=end code
@@ -1035,9 +1036,6 @@ c (Int); #Undefined
10351036
c 42; #Defined
10361037
=end code
10371038

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-
10411039
=head1 Dynamic variables
10421040

10431041
L<Dynamic variables|/language/variables#The_*_twigil> are allowed in signatures

0 commit comments

Comments
 (0)