diff --git a/docs/LanguageRef.md b/docs/LanguageRef.md index 3f34875..6a0d8fd 100644 --- a/docs/LanguageRef.md +++ b/docs/LanguageRef.md @@ -184,6 +184,14 @@ func Vec2_operator_eq(self: *Vec2, other: Vec2) -> bool { ... } func Vec2_operator_lt(self: *Vec2, other: Vec2) -> bool { ... } func MyArray_operator_index_get(self: *MyArray, idx: int) -> int { ... } func MyArray_operator_index_set(self: *MyArray, idx: int, value: int) { ... } + +// Closures (capture-less for now) +let add: func(int, int) -> int = |a: int, b: int| -> int { return a + b; }; +let sum: int = add(3, 4); // 7 + +// Closure passed to higher-order function +func Apply(x: int, op: func(int) -> int) -> int { return op(x); } +let doubled: int = Apply(5, |x: int| -> int { return x * 2; }); // 10 ``` --- diff --git a/docs/PHASE8_STRATEGY.md b/docs/PHASE8_STRATEGY.md index 49c6f45..e24df06 100644 --- a/docs/PHASE8_STRATEGY.md +++ b/docs/PHASE8_STRATEGY.md @@ -294,6 +294,7 @@ Crates.io е непреодолимо предимство. Ние се конк - ✅ defer, switch/case, operator overloading — готово - ✅ `bux new`, `bux init`, `bux test`, `bux fmt` — готово - ✅ Basic borrow checker (`@[Checked]`) — готово +- ✅ Closures (capture-less anonymous functions) — готово - 🎯 Target: Можеш да напишеш `bux` package manager на Bux ### Milestone B: "Използваем за systems programming" (2 месеца) diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 44aaa36..3c75b14 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -236,6 +236,7 @@ Task::Spawn(Worker, rx); 5. ✅ **Named/default parameters** — Done 6. ✅ **Basic borrow checker (`@[Checked]`)** — Done (selfhost) 7. ✅ **`bux fmt`, `bux test`, `bux new`, `bux init`** — Done (selfhost) -8. **Closures** — High complexity, unlocks iterators and functional style. **← NEXT** -9. **`for x in collection`** — Depends on closures or trait system. -10. **Destructors / Drop** — High complexity, needs ownership + move semantics. +8. ✅ **Closures (capture-less)** — Done. Enables callbacks and higher-order functions. +9. **Closures with captures** — Needs capture analysis + environment struct. **← NEXT** +10. **`for x in collection`** — Depends on closures with captures or trait system. +11. **Destructors / Drop** — High complexity, needs ownership + move semantics.