Skip to content

Commit f2040d0

Browse files
committed
Attempt to document 「$foo.bar: |@A」 trap
See issue #602.
1 parent 27721a0 commit f2040d0

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

doc/Language/traps.pod6

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,35 @@ The nice thing about the distinction here is that it gives the developer the
675675
option of passing pairs as either named or positional arguments, which can be
676676
handy in various instances.
677677
678+
=head2 Argument Count Limit
679+
680+
While it is typically unnoticeable, there is a backend-dependent
681+
argument count limit. Any code that does flattening of arbitrarily
682+
sized arrays into arguments won't work if there are too many elements.
683+
684+
=for code
685+
my @a = 1 xx 9999;
686+
my @b;
687+
@b.push: |@a;
688+
say @b.elems # OUTPUT: «9999␤»
689+
690+
=for code
691+
my @a = 1 xx 999999;
692+
my @b;
693+
@b.push: |@a; # OUTPUT: «Too many arguments in flattening array.␤ in block <unit> at <tmp> line 1␤␤»
694+
695+
696+
Avoid this trap by rewriting the code so that there is no
697+
flattening. In the example above, you can replace C<push> with
698+
C<append>. This way, no flattening is required because the array can
699+
be passed as is.
700+
701+
=for code
702+
my @a = 1 xx 999999;
703+
my @b;
704+
@b.append: @a;
705+
say @b.elems # OUTPUT: «999999␤»
706+
678707
=head1 Input and Output
679708
680709
=head2 Closing Open File Handles and Pipes

0 commit comments

Comments
 (0)