|
6 | 6 |
|
7 | 7 | Lists have been a central part of computing since before there
|
8 | 8 | were computers, during which time many devils have taken up residence in
|
9 |
| -their details. They were actually one of the hardest parts of Perl 6 |
| 9 | +their details. They were actually one of the hardest parts of Perl 6 |
10 | 10 | to design, but through persistence and patience, Perl 6 has arrived with
|
11 | 11 | an elegant system for handling them.
|
12 | 12 |
|
13 | 13 | =head1 Literal Lists
|
14 | 14 |
|
15 |
| -Literal L<C<List>s|/type/List> are created with commas B<not> with |
16 |
| -parentheses, so: |
| 15 | +Literal L<C<List>s|/type/List> are created with commas and semicolons B<not> |
| 16 | +with parentheses, so: |
17 | 17 |
|
18 | 18 | 1, 2 # This is two-element list
|
19 |
| - (1, 2) # This is also a list, in parentheses |
20 |
| - (1) # This is not a list, just a 1 in parentheses |
21 |
| - (1,) # This is a one-element list |
| 19 | + (1, 2) # This is also a List, in parentheses |
| 20 | + (1; 2) # same List |
| 21 | + (1) # This is not a List, just a 1 in parentheses |
| 22 | + (1,) # This is a one-element List |
22 | 23 |
|
23 |
| -Parentheses can be used to mark the beginning and end of a list, so: |
| 24 | +Parentheses can be used to mark the beginning and end of a C<List>, so: |
24 | 25 |
|
25 | 26 | (1, 2), (1, 2) # This is a list of two lists.
|
26 | 27 |
|
| 28 | +Multidimensional literal C<List>s are created combining comma and semicolon. |
| 29 | +They can be used in routine argument lists and subscripts. |
| 30 | +
|
| 31 | + say so (1,2; 3,4) eqv ((1,2), (3,4)); |
| 32 | + # OUTPUT«True» |
| 33 | + say('foo';); # a list with one element and the empty list |
| 34 | + # OUTPUT«(foo)()» |
| 35 | +
|
27 | 36 | Individual elements can be pulled out of a list using a subscript. The
|
28 | 37 | first element of a list is at index number zero:
|
29 | 38 |
|
|
0 commit comments