thp-lang.org/md/learn/data-structures/arrays.md

37 lines
438 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-02-20 10:17:21 +00:00
val fruits = ["apple", "banana", "cherry"]
val apple = fruits[0]
2023-10-02 01:41:38 +00:00
2024-03-16 14:30:32 +00:00
print(apple) // apple
2023-10-02 01:41:38 +00:00
2024-03-13 17:16:29 +00:00
var 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