2023-10-02 01:41:38 +00:00
|
|
|
# Arrays
|
|
|
|
|
|
|
|
No destructuring (for now?). There's no `[]` syntax
|
|
|
|
for constructing arrays
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
```thp
|
2023-12-17 01:33:55 +00:00
|
|
|
let fruits = Array("apple", "banana", "cherry")
|
|
|
|
let apple = fruits.[0]
|
2023-10-02 01:41:38 +00:00
|
|
|
|
|
|
|
print(apple)
|
|
|
|
|
|
|
|
|
2023-12-17 01:33:55 +00:00
|
|
|
let mut numbers = Array(0, 1, 2, 3)
|
2023-10-02 01:41:38 +00:00
|
|
|
|
|
|
|
// Note the dot
|
|
|
|
numbers.[3] = 5
|
|
|
|
|
|
|
|
print(numbers.[3]) // 5
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## Type signature
|
|
|
|
|
|
|
|
|
|
|
|
```thp
|
|
|
|
Array[String]
|
|
|
|
Array[Int]
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|