Use return to send a value back to the caller.
double |value I32| -> I32:
return value * 2
;
A function can return more than one success value:
pair || -> String, I32:
return "Priya", 2
;
name, count = pair()
The number of receiving names must match the number of returned success values.
Prefix a receiving name with ~ to update an existing mutable binding. Leave new receiving names unmarked, for example ~count, message = next().
A function with no success values may fall through. That is not the same as -> !, which means the function never returns at all.
Functions that can fail add one final error return marked with !. The Errors page explains how to propagate or recover from that path.
return produces the success values declared by a function.
double |value I32| -> I32:
return value * 2
;
Success returns
- Return values must match the declared success-slot count.
- Each return value must be compatible with its corresponding slot type.
- A function with required success values must return or otherwise terminate on every reachable path.
- A function with no success slots may reach the end of its body.
return with no values can leave a no-success function early.Void is not an explicit return-slot type.- Ordinary no-value completion is not Never. A function that omits
-> may fall through. A function declared -> ! cannot.
Return slots are exact receivers for eligible numeric origins in the function body. They cannot retag an already concrete operation or infer named operands backwards. Completed function signatures and public interfaces contain no pending numeric identity.
Never versus ordinary returns
Three contracts are distinct:
- Omit
-> for ordinary no-success completion. The function may reach the end of its body or use a bare return. - Write an ordinary return type, including a temporary placeholder such as
-> String, when callers should still see that type. The current body may diverge without becoming Never to those callers. - Write
-> ! only when the callable never returns control normally.
greet |name String|:
io.line([: Hello, [name]])
;
load_name || -> String:
assert(false, "not implemented")
;
fatal |message String| -> !:
assert(false, message)
;
Only the explicit -> ! contract propagates divergence across a call. Callers of load_name still see an ordinary String result. See Function declarations for body validation and Calls and access for placement.
Multiple success values
A function may declare and return more than one success value.
pair || -> String, I32:
return "Priya", 2
;
name, count = pair()
The receiving multi-bind must match the success arity.
Each target independently declares a new binding or updates an existing place. An update requires a leading ~ on that target:
next || -> I32, String:
return 1, "ready"
;
count ~= 0
~count, message = next()
An unmarked target must name a new binding. A prefixed target must name an existing mutable binding. New mutable targets retain the explicit-type form, such as count ~I32, message String = next().
The producer runs once and all incoming results are read before any existing target is written. Updates through mutable aliases write through to their referents. These receiving rules also apply to value-producing if, match, catch and propagated multiple-result calls.
Multi-bind targets may continue on a following line only after a comma:
name,
count = pair()
A comma promises another target, so a trailing comma before = is invalid. This is the same continuation rule used by delimiter-free dependency selections. Delimited collections and call arguments keep their own list grammar.
Multi-bind targets are runtime bindings. A # compile-time marker is invalid on every target, new or existing, so name #, count = pair() and name #String, count = pair() are rejected.
Multiple return values are not a user-visible tuple value. A normal single-target declaration cannot receive a multi-return call.
Value-producing if, full matches and catch blocks can also satisfy multi-value receiving sites when every producing path has the required arity.
Error slot shape
A function signature may contain at most one error-channel slot marked with !.
That slot must be last.
load |id String| -> String, Error!:
if id is "":
return! Error("Missing id")
;
return "value"
;
return!, postfix propagation and catch are documented by Errors, options and assertions.
Checked numeric failure is implicit built-in failure, not an undeclared custom error slot. Private functions without an error slot infer and propagate it within the same module, without postfix ! at each internal call. Built-in Error! materialises that failure. A custom E! function must recover locally or map it explicitly.
Exported callables have closed error contracts. An exported callable without an error slot must discharge implicit failure or receive a compiler diagnostic. Traits and generic conformance cannot secretly widen that signature. The compiler-owned entry has built-in Error!; compatible top-level postfix ! is legal, while custom errors still need explicit recovery.
Return contract
Return slots contain types and channels only. Source code has no borrowed, owned, move or parameter-alias return annotation.
Returning an existing value follows ordinary shared-reference semantics. The compiler infers freshness and alias effects from validated bodies and calls. Public interfaces preserve those inferred relationships. External bindings may declare equivalent alias behaviour because their foreign bodies are unavailable.
Binding freshness and allocation identity
Every function result enters a fresh caller binding. This does not imply a fresh allocation. Returning an existing record, collection, map, string allocation, opaque handle or projection preserves its allocation identity and lifetime owner. The result binding never points at the callee's parameter or local binding slot.
Reassigning one binding does not rebind another binding that received the same allocation through a return. The allocation remains alive while any legal alias retains it.
Ordinary return does not copy. Use copy when the caller needs an independent result graph.
Inferred alias relationships govern borrow and lifetime validation without changing the source type.
External alias metadata describes whether a foreign result aliases an argument allocation. It does not expose binding references to source code and does not allow host code to return a Moth binding cell.
Fallible and multiple returns
Fallible success values may alias a parameter allocation. Multiple return values may alias parameters or each other. Each returned value enters its own caller binding, defined only on the successful path. The separate error channel defines no success value on failure. Any physical result carrier belongs to the target ABI and proves neither fresh allocations nor disjoint results. Runtime lowering preserves those allocation relationships.