Skip to content

Commit 62327f8

Browse files
author
Leo Louvar
committed
Docs: add Indexing subsection, README grammar, rebuild PDF for website
Made-with: Cursor
1 parent 4128229 commit 62327f8

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Elixir orchestrates and restarts failed workers; Zig runs hot-path code; Python
3939

4040
### How it works
4141

42-
Zixir has its **own grammar** (`let`, expressions, `engine.op(args)`, `python "module" "function" (args)`, literals, binary ops, 25+ built-in functions). Source is **parsed** in Elixir into a Zixir AST, then either:
42+
Zixir has its **own grammar** (`let`, expressions, array/map indexing `arr[i]` and `map["key"]`, `engine.op(args)`, `python "module" "function" (args)`, literals, binary ops, 25+ built-in functions). Source is **parsed** in Elixir into a Zixir AST, then either:
4343

4444
- **Interpreted**`Zixir.eval(source)` evaluates the AST in Elixir; `engine.*` calls run in Zig NIFs, `python` calls go to Python via a port.
4545
- **Compiled**`Zixir.Compiler.compile(source)` type-checks, optimizes, and **emits Zig**; the Zig is compiled to a native binary or run JIT.

docs/Zixir Language complete guide.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,27 @@ let all_values = values(user) # ["Alice Johnson", 28, "alice@example.com"]
563563
let size = length(user) # 3
564564
```
565565

566+
### Indexing (arrays and maps)
567+
568+
Zixir uses **bracket notation** for both array and map access:
569+
570+
| Target | Syntax | Index/key | Result |
571+
|--------|--------|-----------|--------|
572+
| **Array** | `arr[i]` | Integer, zero-based | Element at position `i`; error if out of bounds |
573+
| **Map** | `map["key"]` | Any value (often string) | Value for key, or `nil` if key missing |
574+
575+
**Array indexing:** Zero-based and bounds-checked. Use a variable (or expression) on the left: `let arr = [1, 2, 3]` then `arr[0]`. Last element: `arr[length(arr) - 1]`.
576+
577+
**Map indexing:** `user["name"]` returns the value or `nil` if the key is missing. Nested: `company["address"]["city"]`.
578+
579+
```zixir
580+
let arr = [10, 20, 30]
581+
arr[0] # 10
582+
let m = {"a": 1, "b": 2}
583+
m["a"] # 1
584+
m["missing"] # nil
585+
```
586+
566587
### Type Conversions
567588

568589
Zixir provides built-in functions for type conversion:
16.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)