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>
688 B
688 B
id: fn-unwrap_or name: unwrap_or category: builtins kind: builtin tokens: unwrap_or sig: unwrap_or(o: option, fallback) -> int tip: The option value, or a fallback if empty. order: 20
Reads an option: returns its value when it is some, or fallback when it is none. The safe, one-line way to get a usable value out of an option without a separate branch.
Parameters:
o— the option to readfallback— the value to use when the option is empty
program Config {
handler Step phase Update {
let volume = unwrap_or(none(), 100) # default to 100
}
}