Skip to content

Commit

Permalink
Bring prose about Array constructor up to date
Browse files Browse the repository at this point in the history
Fixes #1229
  • Loading branch information
zoffixznet committed May 6, 2017
1 parent 0728c55 commit f6472b6
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions doc/Language/syntax.pod6
Expand Up @@ -442,15 +442,20 @@ inside:
say ['a', 'b', 42].join(' '); # OUTPUT: «a b 42␤»
# ^^^^^^^^^^^^^^ Array constructor
The array constructor flattens non-itemized arrays and lists, but not itemized
arrays themselves:
If the constructor is given a single L<Iterable>, it'll clone and flatten it.
If you want an C<Array> with just 1 element that is that C<Iterable>, ensure
to use a comma after it:
my @a = 1, 2;
# flattens:
say [@a, 3, 4].elems; # OUTPUT: «4␤»
say [@a].perl; # OUTPUT: «[1, 2]␤»
say [@a,].perl; # OUTPUT: «[[1, 2],]␤»
# does not flatten:
say [[@a], [3, 4]].elems; # OUTPUT: «2␤»
The C<Array> constructor does not flatten other types of contents.
Use the L<Slip> prefix operator (C<|>) to flatten the needed items:
my @a = 1, 2;
say [@a, 3, 4].perl; # OUTPUT: «[[1, 2], 3, 4]␤»
say [|@a, 3, 4].perl; # OUTPUT: «[1, 2, 3, 4]␤»
=head3 Hash literals
Expand Down

0 comments on commit f6472b6

Please sign in to comment.