Skip to content

Commit 62184ce

Browse files
HaraldJoergkhwilliamson
authored andcommitted
[PATCH] Docu suggestion for named parameters in signatures
Add a paragraph that callers need to specify all positional parameters before named ones, even if the positional parameters have defaults. Delete a sentence stating that there is no way for the caller to provide a value for a named parameter after an optional positional parameter. There _is_ a way, you just need to provide values for positional parameters.
1 parent 4092daf commit 62184ce

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

pod/perlsub.pod

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,11 @@ is not important; both of the following lines will cause the same behaviour:
476476
foo(alpha => "A", beta => "B");
477477
foo(beta => "B", alpha => "A");
478478

479+
If a function declares both positional and named parameters, then
480+
callers must provide values for all positional parameters before
481+
providing values for named parameters, even if the positional
482+
parameters have default values.
483+
479484
It is not important where these parameter names come from in the caller. In
480485
simple cases they could be literal strings such as the previous example, or
481486
they could themselves come from other variables. Expanding a hash variable
@@ -507,12 +512,10 @@ left to right, as required. As with positional parameters, each expression
507512
can see and make use of the values assigned to any previous parameter.
508513

509514
If the subroutine already declares any optional positional parameters, then
510-
all named parameters must also be optional. It would not make sense to
511-
require a mandatory named parameter after any optional positional ones, as
512-
there would be no way for the caller to provide a value for it. However, if
513-
the subroutine does not declare any optional positional parameters, then any
514-
named ones may be freely mixed between mandatory and optional, since they are
515-
processed by name and not position.
515+
all named parameters must also be optional. However, if the subroutine does
516+
not declare any optional positional parameters, then any named ones may be
517+
freely mixed between mandatory and optional, since they are processed by
518+
name and not position.
516519

517520
After positional or named parameters, additional arguments may be captured
518521
in a slurpy parameter. The simplest form of this is just an array variable:
@@ -1644,7 +1647,7 @@ example, satisfies C<\%>:
16441647
my %hash
16451648
$hashref->%*
16461649
%{ expr }
1647-
(expr)->*%
1650+
(expr)->%*
16481651

16491652
The value passed as part of C<@_> will be a
16501653
reference to the actual argument given in the subroutine call,

0 commit comments

Comments
 (0)