aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorBobby <[email protected]>2024-04-04 16:25:56 +0000
committerBobby <[email protected]>2024-04-04 16:25:56 +0000
commit77d0ea46b3f1de99357c7706c4c05eb44c237412 (patch)
treed6fa8ca0a89233b26591eaed72c1017ad6190dba /README.md
parent3d4f24f7c4ea05471109c0b13abbc95e70c6924b (diff)
downloadmana-77d0ea46b3f1de99357c7706c4c05eb44c237412.tar.xz
mana-77d0ea46b3f1de99357c7706c4c05eb44c237412.zip
arrays and array indexes
Diffstat (limited to 'README.md')
-rw-r--r--README.md27
1 files changed, 25 insertions, 2 deletions
diff --git a/README.md b/README.md
index 907ceac..fcc80f8 100644
--- a/README.md
+++ b/README.md
@@ -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: