Result Cheatsheet
This page is the shortest path through the v0.33.x Result handling
surface. If an older page says ?! calls failsafe, ?? handles
Result<T> errors, or catch is a hard keyword, this page wins.
Creation and function exits
| Surface | Use | Notes |
|---|---|---|
pass value |
Return success from an ordinary function | Wraps value as Result<T> success. |
fail code |
Return failure from an ordinary function | code is currently source-facing int32 error-code reality. |
pass NIL |
Return success from func:f = NIL(...) |
The void-shaped form is Result<NIL>. |
exit code |
Leave main / failsafe |
main and failsafe do not use pass / fail. |
Handling Results
| Surface | Meaning | Example |
|---|---|---|
expr ? fallback |
Result fallback unwrap | int32:x = maybe() ? 0i32; |
expr ?! fallback |
Emphatic Result fallback unwrap | int32:x = maybe() ?! 0i32; |
expr ?| fallback |
defaults shorthand |
int32:x = a() + b() ?| 0i32; |
expr defaults fallback |
Scoped expression fallback | int32:x = a() + b() defaults 0i32; |
expr catch (err) { handler } |
Error-aware fallback | int32:x = maybe() catch (err) { err + 10i32 }; |
raw expr |
Extract value, ignore error | int32:x = raw maybe(); |
_! expr |
Shorthand for raw expr |
int32:x = _! maybe(); |
drop expr |
Evaluate and discard | drop setup(); |
_? expr |
Shorthand for drop expr |
_? setup(); |
Null / Optional handling
| Surface | Meaning | Result behavior |
|---|---|---|
expr ?? fallback |
Optional/pointer null coalesce | Result<T> ?? fallback is rejected. |
receiver?.field |
Optional/pointer/struct safe navigation | Result receivers are rejected. |
The big gotchas
?is fallback unwrap, not hidden propagation.?!is emphatic fallback unwrap, not source-level failsafe dispatch.??is null/Optional coalescing, not Result error coalescing._?and_!are prefix shorthands.catchis contextual only; it remains a valid identifier elsewhere.defaults/?|have a low-precedence left side, but the fallback is a primary expression in the shipped parser.
Choosing a surface
| You want to... | Use |
|---|---|
| return success | pass value |
| return failure | fail code |
| unwrap with a constant fallback | expr ? fallback |
| unwrap with a fallback that depends on the error | expr catch (err) { handler } |
| give a whole expression chain one fallback | expr defaults fallback or expr ?| fallback |
| ignore failure state intentionally | raw expr / _! expr |
| discard the value intentionally | drop expr / _? expr |
| handle Optional/pointer null | ?? or ?. |