diff options
| author | Bobby <[email protected]> | 2024-04-10 20:42:41 +0000 |
|---|---|---|
| committer | Bobby <[email protected]> | 2024-04-10 20:42:41 +0000 |
| commit | ca46690f9166681e4b32af90e28fb215c12f76c0 (patch) | |
| tree | 1b8ac7bf26616bcc0bdc3038221997d30d66d751 /README.md | |
| parent | e7b7baba5e6485ae6e241eee4c3f30557afa0fa8 (diff) | |
| download | mana-ca46690f9166681e4b32af90e28fb215c12f76c0.tar.xz mana-ca46690f9166681e4b32af90e28fb215c12f76c0.zip | |
hashes
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 21 |
1 files changed, 20 insertions, 1 deletions
@@ -27,7 +27,7 @@ Mana is a toy programming language written in Go. It is a dynamically typed, int | `BuiltInFunctions` | ✔️ | Built-in Functions are functions that are built into the language | `len("Hello, World!")` | ✔️ | | `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 | +| `HashLiteralExpression` | ✔️ | Hash Literal Expressions are used to represent hash values | `{"key": "value"}` | ✔️ | \*_NYI = Not Yet Implemented_ @@ -178,6 +178,25 @@ let u = ["one", "two", 3][5 - 4]; // u = "two" let k = mixed[c - 67]; // k = true ``` +## Hashes + +Hashes in Mana are unordered collections of key-value pairs. Hashes are created using curly braces. Hashes can contain keys of `supported types` (**Boolean**, **Integers**, and **Strings** - Objects which implement the `Hashable` interface). Hashes can contain values of any type, including other hashes. Hashes are indexed using square brackets. The index is a key that represents the key of the element in the hash. + +```rust +let person = { + "name": "Alice", + "age": 30, + "isStudent": false, + "address": { + "street": "123 Main St", + "city": "Anytown" + } +}; + +let name = person["name"]; // name = "Alice" +let city = person["address"]["city"]; // city = "Anytown" +``` + ## Building Advanced Functions **Map** |
