Skip to content

Commit e0d5770

Browse files
committed
Link Scalar, Array and Iterable in Slurpy parameters section.
Also use code blocks for examples.
1 parent 9d392d1 commit e0d5770

File tree

1 file changed

+37
-31
lines changed

1 file changed

+37
-31
lines changed

doc/Type/Signature.pod6

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,8 @@ Note that positional parameters aren't allowed after slurpy parameters.
419419
# Cannot put required parameter $last after variadic parameters
420420
=end code
421421
422-
Normally a slurpy parameter will create an Array, create a new
423-
Scalar container for each argument, and assign the value from each
422+
Normally a slurpy parameter will create an L<Array|/type/Array>, create a new
423+
L<Scalar|/type/Scalar> container for each argument, and assign the value from each
424424
argument to those Scalars. If the original argument also had an
425425
intermediary Scalar it is bypassed during this process, and
426426
is not available inside the called function.
@@ -446,54 +446,60 @@ each slurpy convention varies from the others.
446446
=head3 Flattened Slurpy
447447
448448
Slurpy parameters declared with one asterisk will flatten arguments by
449-
dissolving one or more layers of bare C<Iterables>.
450-
451-
my @array = <a b c>;
452-
my $list := <d e f>;
453-
sub a(*@a) { @a.perl.say };
454-
a(@array); # OUTPUT: «["a", "b", "c"]»
455-
a(1, $list, [2, 3]); # OUTPUT: «[1, "d", "e", "f", 2, 3]»
456-
a([1, 2]); # OUTPUT: «[1, 2]»
457-
a(1, [1, 2], ([3, 4], 5)); # OUTPUT: «[1, 1, 2, 3, 4 5]»
458-
a(($_ for 1, 2, 3)); # OUTPUT: «[1, 2, 3]»
449+
dissolving one or more layers of bare L<Iterable|/type/Iterable>s.
450+
451+
=begin code
452+
my @array = <a b c>;
453+
my $list := <d e f>;
454+
sub a(*@a) { @a.perl.say };
455+
a(@array); # OUTPUT: «["a", "b", "c"]»
456+
a(1, $list, [2, 3]); # OUTPUT: «[1, "d", "e", "f", 2, 3]»
457+
a([1, 2]); # OUTPUT: «[1, 2]»
458+
a(1, [1, 2], ([3, 4], 5)); # OUTPUT: «[1, 1, 2, 3, 4 5]»
459+
a(($_ for 1, 2, 3)); # OUTPUT: «[1, 2, 3]»
460+
=end code
459461
460462
A single asterisk slurpy flattens all given iterables, effectively hoisting any
461463
object created with commas up to the top level.
462464
463465
=head3 Unflattened Slurpy
464466
465-
Slurpy parameters declared with two stars do not flatten any iterable arguments
467+
Slurpy parameters declared with two stars do not flatten any L<Iterable|/type/Iterable> arguments
466468
within the list, but keep the arguments more or less as-is:
467469
468-
my @array = <a b c>;
469-
my $list := <d e f>;
470-
sub b(**@b) { @b.perl.say };
471-
b(@array); # OUTPUT: «[["a", "b", "c"],]␤»
472-
b(1, $list, [2, 3]); # OUTPUT: «[1, ("d", "e", "f"), [2, 3]]␤»
473-
b([1, 2]); # OUTPUT: «[[1, 2],]␤»
474-
b(1, [1, 2], ([3, 4], 5)); # OUTPUT: «[1, [1, 2], ([3, 4], 5)]␤»
475-
b(($_ for 1, 2, 3)); # OUTPUT: «[(1, 2, 3),]␤»
470+
=begin code
471+
my @array = <a b c>;
472+
my $list := <d e f>;
473+
sub b(**@b) { @b.perl.say };
474+
b(@array); # OUTPUT: «[["a", "b", "c"],]␤»
475+
b(1, $list, [2, 3]); # OUTPUT: «[1, ("d", "e", "f"), [2, 3]]␤»
476+
b([1, 2]); # OUTPUT: «[[1, 2],]␤»
477+
b(1, [1, 2], ([3, 4], 5)); # OUTPUT: «[1, [1, 2], ([3, 4], 5)]␤»
478+
b(($_ for 1, 2, 3)); # OUTPUT: «[(1, 2, 3),]␤»
479+
=end code
476480
477481
The double asterisk slurpy hides the nested comma objects and leaves them as-is
478482
in the slurpy array.
479483
480484
=head3 Single Argument Rule Slurpy
481485
X<|+ (Single Argument Rule Slurpy)>
482486
483-
A slurpy parameter created using a plus engages the "single argument rule",
487+
A slurpy parameter created using a plus engages the I<"single argument rule">,
484488
which decides how to handle the slurpy argument based upon context. Basically,
485-
if only a single argument is passed and that argument is iterable, that argument
489+
if only a single argument is passed and that argument is L<Iterable|/type/Iterable>, that argument
486490
is used to fill the slurpy parameter array. In any other case, C<+@> works like
487491
C<**@>.
488492
489-
my @array = <a b c>;
490-
my $list := <d e f>;
491-
sub c(+@b) { @b.perl.say };
492-
c(@array); # OUTPUT: «["a", "b", "c"]␤»
493-
c(1, $list, [2, 3]); # OUTPUT: «[1, ("d", "e", "f"), [2, 3]]␤»
494-
c([1, 2]); # OUTPUT: «[1, 2]␤»
495-
c(1, [1, 2], ([3, 4], 5)); # OUTPUT: «[1, [1, 2], ([3, 4], 5)]␤»
496-
c(($_ for 1, 2, 3)); # OUTPUT: «[1, 2, 3]␤»
493+
=begin code
494+
my @array = <a b c>;
495+
my $list := <d e f>;
496+
sub c(+@b) { @b.perl.say };
497+
c(@array); # OUTPUT: «["a", "b", "c"]␤»
498+
c(1, $list, [2, 3]); # OUTPUT: «[1, ("d", "e", "f"), [2, 3]]␤»
499+
c([1, 2]); # OUTPUT: «[1, 2]␤»
500+
c(1, [1, 2], ([3, 4], 5)); # OUTPUT: «[1, [1, 2], ([3, 4], 5)]␤»
501+
c(($_ for 1, 2, 3)); # OUTPUT: «[1, 2, 3]␤»
502+
=end code
497503
498504
For additional discussion and examples, see L<Slurpy Conventions for Functions|/language/functions#Slurpy_Conventions>.
499505

0 commit comments

Comments
 (0)