Recoverable results
ASPL 0.7.0 · Current release
Current 0.7.0 operations, host support, examples, and failure rules.
On this page
Recoverable values
On both ASPL 0.7.0 hosts, نتيجة<T>/result<T> contains a successful T payload or معلومات_خطأ/error_info. A failed result is ordinary control flow: it emits no diagnostic, source span, or stack trace and does not stop execution. You choose whether to retry, continue, or return a process status.
نجاح/success(value) infers its payload type or checks against an expected result type. success() creates result<unit>, a success with no payload. إخفاق/failure(code, message) takes two strings and needs the expected result type from a declaration, assignment, argument, or return. Without that context, checking fails with result-type-required.
Check before reading a branch
| Field | Receiver | Type |
|---|---|---|
نجاح/ok |
result<T> |
bool |
قيمة/value |
successful result<T> |
T, except unit |
الخطأ/error |
failed result<T> |
error_info |
الرمز/code |
error_info |
string |
الرسالة/message |
error_info |
string |
Use postfix :: and test ok before reading the corresponding branch. value on failure or error on success traps with wrong-result-branch. A result<unit> has no readable value; trying to read it is a source error, unit-value-not-allowed. Whole-result equality is rejected. Field access binds more tightly than arithmetic and does not translate user record fields.
Execution: Browser and native · ASPL 0.7.0
- No prior knowledge is required to open and check it.
Input: No input lines are required.
fn greet(name: string) -> result<string> {
if (name matches "") {
return failure("empty-name", "name was empty");
}
return success("hello " + name);
}
fn start_main() -> i64 {
let valid: result<string> = greet("aspl");
if (valid::ok) {
print(valid::value);
print(" ");
} else {
return 1;
}
let invalid: result<string> = greet("");
if (invalid::ok) {
return 2;
}
print(invalid::error::code);
return 0;
}
Expected outcomes
{
"browser": {
"check": "success",
"class": "success",
"output": "hello aspl empty-name",
"processStatus": 0
},
"native": {
"check": 0,
"status": 0,
"output": "hello aspl empty-name"
}
}Codes, messages, and copies
Branch on stable error codes such as invalid-number, number-out-of-range, and not-found, not message wording. Your own function chooses its own codes and messages. Results and retained payloads have value semantics; result projections are read-only. Assign a payload to a var binding to modify your copy.
Distinct kinds of failure
Bad numeric text and expected text-file failures return results. Invalid types or fields prevent checking. Out-of-bounds indexing and wrong-branch access are uncatchable traps. Memory/time limits, allocation failure, and Stop are separate execution outcomes; they are not failed results you can catch.
The parsing examples and file guide show recovery while the program continues. Diagnostics explains source errors and traps.
Scope and complete examples
Recoverable results extend the historical MVP. Read every supplied results variant and the text-file API for result<string> reads and result<unit> writes.