Skip to content

Commit

Permalink
🐛 closes Raku#4012
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ committed Mar 26, 2022
1 parent 1f8c9d4 commit cdcfb34
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions doc/Type/Signature.pod6
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,10 @@ parameter by name, for instance to distinguish between different signatures in a
L<multi|/language/functions#index-entry-declarator_multi-Multi-dispatch> or to
check the signature of a L<Callable|/type/Callable>.
my $sig = :($, @, %a); # two anonymous and a "normal" parameter
$sig = :(Int, Positional); # just a type is also fine (two parameters)
sub baz(Str) { "Got passed a Str" }
=for code :preamble<my $sig;>
my $sig = :($, @, %a); # two anonymous and a "normal" parameter
$sig = :(Int, Positional); # just a type is also fine (two parameters)
sub baz(Str) { "Got passed a Str" }
Type constraints may also be L<type captures|/type/Signature#Type_captures>.
Expand Down Expand Up @@ -842,10 +843,11 @@ positional, except slurpy hash and arguments marked with a leading colon C<:>.
The latter is called a L<colon-pair|/type/Pair>. Check the following signatures
and what they denote:
$sig1 = :($a); # a positional argument
$sig2 = :(:$a); # a named argument of name 'a'
$sig3 = :(*@a); # a slurpy positional argument
$sig4 = :(*%h); # a slurpy named argument
=for code :preamble<my ($sig1, $sig2, $sig3, $sig4);>
$sig1 = :($a); # a positional argument
$sig2 = :(:$a); # a named argument of name 'a'
$sig3 = :(*@a); # a slurpy positional argument
$sig4 = :(*%h); # a slurpy named argument
On the caller side, positional arguments are passed in the same order as the
arguments are declared.
Expand Down Expand Up @@ -961,23 +963,27 @@ X<|optional argument>
Positional parameters are mandatory by default, and can be made optional
with a default value or a trailing question mark:
$sig1 = :(Str $id); # required parameter
$sig2 = :($base = 10); # optional parameter, default value 10
$sig3 = :(Int $x?); # optional parameter, default is the Int type object
=for code :preamble<my ($sig1, $sig2, $sig3);>
$sig1 = :(Str $id); # required parameter
$sig2 = :($base = 10); # optional parameter, default value 10
$sig3 = :(Int $x?); # optional parameter, default is the Int type object
X<|mandatory named argument>
Named parameters are optional by default, and can be made mandatory with a
trailing exclamation mark:
$sig1 = :(:%config); # optional parameter
$sig2 = :(:$debug = False); # optional parameter, defaults to False
$sig3 = :(:$name!); # mandatory 'name' named parameter
=for code :preamble<my ($sig1, $sig2, $sig3);>
$sig1 = :(:%config); # optional parameter
$sig2 = :(:$debug = False); # optional parameter, defaults to False
$sig3 = :(:$name!); # mandatory 'name' named parameter
Default values can depend on previous parameters, and are (at least
notionally) computed anew for each call
$sig1 = :($goal, $accuracy = $goal / 100);
$sig2 = :(:$excludes = ['.', '..']); # a new Array for every call
=begin code :preamble<my ($sig1, $sig2);>
$sig1 = :($goal, $accuracy = $goal / 100);
$sig2 = :(:$excludes = ['.', '..']); # a new Array for every call
=end code
=head2 Dynamic variables
Expand Down

0 comments on commit cdcfb34

Please sign in to comment.