thp-web/md/learn/collections/arrays.md

37 lines
432 B
Markdown
Raw Normal View History

2023-10-02 01:41:38 +00:00
# Arrays
2024-01-01 14:11:41 +00:00
Use square brackets as usual.
2023-10-02 01:41:38 +00:00
## Usage
```thp
2024-01-01 14:11:41 +00:00
let fruits = ["apple", "banana", "cherry"]
let apple = fruits[0]
2023-10-02 01:41:38 +00:00
print(apple)
2024-01-01 14:11:41 +00:00
let mut numbers = [0, 1, 2, 3]
2023-10-02 01:41:38 +00:00
2024-01-01 14:11:41 +00:00
numbers[3] = 5
2023-10-02 01:41:38 +00:00
2024-01-01 14:11:41 +00:00
print(numbers[3]) // 5
2023-10-02 01:41:38 +00:00
```
## Type signature
```thp
Array[String]
Array[Int]
```
2024-01-01 14:11:41 +00:00
The Array signature __requires__ the word `Array`.
There is no `Int[]` or `[Int]` signature, since that would cause
problems with the language's grammar.
2023-10-02 01:41:38 +00:00