diff options
| author | Bobby <[email protected]> | 2024-04-04 16:25:56 +0000 |
|---|---|---|
| committer | Bobby <[email protected]> | 2024-04-04 16:25:56 +0000 |
| commit | 77d0ea46b3f1de99357c7706c4c05eb44c237412 (patch) | |
| tree | d6fa8ca0a89233b26591eaed72c1017ad6190dba /README.md | |
| parent | 3d4f24f7c4ea05471109c0b13abbc95e70c6924b (diff) | |
| download | mana-77d0ea46b3f1de99357c7706c4c05eb44c237412.tar.xz mana-77d0ea46b3f1de99357c7706c4c05eb44c237412.zip | |
arrays and array indexes
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 27 |
1 files changed, 25 insertions, 2 deletions
@@ -25,8 +25,8 @@ Mana is a toy programming language written in Go. It is a dynamically typed, int | `CallExpression` | ✔️ | Call Expressions are used to call functions | `add(5, 5)` | ✔️ | | `StringLiteralExpression` | ✔️ | String Literal Expressions are used to represent string values | `"Hello, World!"` | ✔️ | | `BuiltInFunctions` | ✔️ | Built-in Functions are functions that are built into the language | `len("Hello, World!")` | ✔️ | -| `ArrayLiteralExpression` | NYI | Array Literal Expressions are used to represent array values | `[1, 2, 3]` | NYI | -| `IndexExpression` | NYI | Index Expressions are used to index into arrays | `myArray[0]` | NYI | +| `ArrayLiteralExpression` | ✔️ | Array Literal Expressions are used to represent array values | `[1, 2, 3]` | ✔️ | +| `IndexExpression` | ✔️ | Index Expressions are used to index into arrays | `myArray[0]` | ✔️ | | `HashLiteralExpression` | NYI | Hash Literal Expressions are used to represent hash values | `{"key": "value"}` | NYI | \*_NYI = Not Yet Implemented_ @@ -151,6 +151,29 @@ let name = "World!"; let message = greeting + name; // message = "Hello, World!" ``` +## Arrays + +Arrays in Mana are ordered collections of values. Arrays are created using square brackets. Arrays can contain values of any type, including other arrays. Arrays are indexed using square brackets. The index is an integer value that represents the position of the element in the array. Arrays are zero-indexed, which means that the first element in the array is at index 0. + +```rust +let numbers = [1, 2, 3, 4, 5]; + +let first = numbers[0]; // first = 1 + +let last = numbers[len(numbers) - 1]; // last = 5 +``` + +```rust +let mixed = [1, "two", true, fn(x) { x * x; }]; +let c = 69; + +let f = mixed[3](5); // f = 25 + +let u = ["one", "two", 3][5 - 4]; // s = "two" + +let k = mixed[c - 67]; // k = true +``` + ## Building the Project To build the project, you will need to have Go installed on your machine. You can download Go from the [official website](https://golang.org/). Once you have Go installed, you can build the project by running the following command: |
