Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add intro for arrays concept #672

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions concepts/arrays-lists-sequences/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
A `List` is an ordered sequence of values.
A `List` is immutable, but if any of the values in a `List` are containers, the values of those containers can be changed.

An `Array` is a type of List which is mutable, i.e., the contents and size of an array can both be changed.

An `Array` can have a type constraint.

`Array`s and `List`s have the `Positional` role, which allows for using the postcircumfix `[]` operator to access elements by their indexes.
This is also known as [positional subscripting][positional-subscripting].

Indexes start at 0.
Raku does not support negative indexes, but instead a code block can be used inside a positional subscript to emulate the same behavior.
The argument to this code block will be the number of elements in the `List`.

```raku
# All of the following will give 'c'
('a', 'b', 'c')[*-1];
('a', 'b', 'c')[{ $_ - 1 }];
('a', 'b', 'c')[-> $elems { $elems - 1 }];
```

[positional-subscripting]: https://docs.raku.org/language/subscripts#Positional_subscripting