Skip to content

Commit f6472b6

Browse files
committed
Bring prose about Array constructor up to date
Fixes #1229
1 parent 0728c55 commit f6472b6

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

doc/Language/syntax.pod6

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -442,15 +442,20 @@ inside:
442442
say ['a', 'b', 42].join(' '); # OUTPUT: «a b 42␤»
443443
# ^^^^^^^^^^^^^^ Array constructor
444444
445-
The array constructor flattens non-itemized arrays and lists, but not itemized
446-
arrays themselves:
445+
If the constructor is given a single L<Iterable>, it'll clone and flatten it.
446+
If you want an C<Array> with just 1 element that is that C<Iterable>, ensure
447+
to use a comma after it:
447448
448449
my @a = 1, 2;
449-
# flattens:
450-
say [@a, 3, 4].elems; # OUTPUT: «4␤»
450+
say [@a].perl; # OUTPUT: «[1, 2]␤»
451+
say [@a,].perl; # OUTPUT: «[[1, 2],]␤»
451452
452-
# does not flatten:
453-
say [[@a], [3, 4]].elems; # OUTPUT: «2␤»
453+
The C<Array> constructor does not flatten other types of contents.
454+
Use the L<Slip> prefix operator (C<|>) to flatten the needed items:
455+
456+
my @a = 1, 2;
457+
say [@a, 3, 4].perl; # OUTPUT: «[[1, 2], 3, 4]␤»
458+
say [|@a, 3, 4].perl; # OUTPUT: «[1, 2, 3, 4]␤»
454459
455460
=head3 Hash literals
456461

0 commit comments

Comments
 (0)