Skip to content

Commit 6bea3e3

Browse files
committed
add explanations and references about indexing
1 parent 856bbc7 commit 6bea3e3

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

doc/Language/list.rakudoc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,23 @@ first element of a list is at index number zero:
7474
say (1, 2)[0]; # says 1
7575
say (1, 2)[1]; # says 2
7676
say (1, 2)[2]; # says Nil
77+
78+
Counting backwards from the end is done with the L<C<Whatever>|/type/Whatever> star
79+
(details on the page on L<Subscripts|/language/subscripts#From_the_end>):
7780
=for code :skip-test<syntax error>
78-
say (1, 2)[-1]; # Error
81+
say (1, 2)[*-1]; # says 2
82+
say (1, 2)[-1]; # Error
83+
84+
To access elements of nested (multidimensional) lists,
85+
separate the indices for different dimensions with semicolons:
7986
=for code
8087
say ((<a b>,<c d>),(<e f>,<g h>))[1;0;1]; # says "f"
8188

89+
Pulling out multiple elements at once is possible
90+
by passing lists or ranges of indices;
91+
this is described in sections L<Slice indexing context|#Slice_indexing_context>
92+
and L<Range as slice|#Range_as_slice>.
93+
8294
=head1 The @ sigil
8395

8496
Variables in Raku whose names bear the C<@> sigil are expected to

0 commit comments

Comments
 (0)