ludic/docs/language/builtins/fn-none.md
Orkuncakilkaya 790eda6f73
All checks were successful
bootstrap / cfree-fixpoint (push) Successful in 20s
ci / build-and-test (push) Successful in 1m31s
commit-lint / conventional-commits (push) Successful in 6s
docs / build-and-deploy (push) Successful in 23s
feat(types): option (some/none) safety type (#53)
Types phase 3 — the option/result safety pair. result/ok/err/try shipped in
#46; this adds its companion option:

- some(v)   -> option   (present value; any i32-width scalar)
- none()    -> option   (empty; no magic -1 sentinel)
- is_some / is_none -> bool
- unwrap_or(o, fallback) -> int

A heap %Option = { i32 present, i32 value }, bare builtins guarded by find_fn
(a user fn of the same name still wins), gated by g_uses_option so unused
programs compile byte-identically — same idiom as result.

Wired: emit_call codegen + %Option decl (emit_decl) + g_uses_option (emit_core),
reseeded seed, vocabulary sync (header/JetBrains/TextMate), builtin docs +
inventory, and a self-asserting example (examples/library/optionresult.ludic +
feat_case). All suites green incl. golden renders byte-identical and the
bootstrap fixpoint.

Tagged-union enums (variant payloads + binding match + exhaustiveness) are the
deep type-system feature, split out to #56.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-31 19:11:27 +03:00

24 lines
763 B
Markdown

---
id: fn-none
name: none
category: builtins
kind: builtin
tokens: none
sig: none() -> option
tip: The empty option — a missing value.
order: 17
---
The empty <code>option</code> — a missing value with no sentinel. Return it when there is nothing to give: no target, an empty slot, a lookup that missed. The caller distinguishes it from <a href="fn-some"><code>some</code></a> with <a href="fn-is_none"><code>is_none</code></a> / <a href="fn-is_some"><code>is_some</code></a>, or supplies a default with <a href="fn-unwrap_or"><code>unwrap_or</code></a>.
```ludic
program Slots {
function held(slot: int) -> option {
if slot < 0 { return none() }
return some(slot)
}
test "none is empty" {
expect_eq(is_none(held(0 - 1)), true)
}
}
```