Skip to content

Commit 5e7a325

Browse files
committed
[List] notes on items, sigils and flattening
1 parent 09c424c commit 5e7a325

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

lib/List.pod

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,35 @@ C<List> stores items sequentially and potentially lazily.
88
99
Indexes into lists and arrays start at 0 by default.
1010
11+
You cannot assign to list elements. Use Arrays for that use
12+
case instead.
13+
14+
15+
=head2 Items, Flattening and Sigils
16+
17+
In Perl 6, assigning a C<List> to a scalar variable does not lose
18+
information. The difference is that iteration generally treats a
19+
list (or any other list-like object, like a C<Parcel> or an C<Array>)
20+
inside a scalar as a single element.
21+
22+
my @a = 1, 2, 3;
23+
for @a { } # three iterations
24+
25+
my $s = @a;
26+
for $s { } # one iteration
27+
for @a.item { } # one iteration
28+
for $s.list { } # three iterations
29+
30+
Combining lists or arrays that are not inclosed into an item container
31+
generally flattens.
32+
33+
my @a = 1, 2, 3;
34+
my @flat = @a, @a; # six elements
35+
my @nested = @a.item, @a.item; # two elemnts
36+
37+
C<.item> can often be written as C<$( ... )>, and on an array variable
38+
even as C<$@a>.
39+
1140
=head2 Methods
1241
1342
=head3 elems

0 commit comments

Comments
 (0)