Handle a recoverable result
ASPL 0.7.0 · Current release
Complete supplied source, preparation, and checked ASPL 0.7.0 outcomes.
On this page
Purpose and preparation
Browser and native, ASPL 0.7.0. Checks success and failure branches, prints hello aspl empty-name, and returns 0. The failed result is handled without a trap.
See the current reference. No source module or external library is required.
Arabic source
This supplied complete source opens a new draft. Prepare the declared inputs/files in that draft, then select Run explicitly.
Execution: Browser and native · ASPL 0.7.0
- No prior knowledge is required to open and check it.
Input: No input lines are required.
دالة حي(الاسم: نص) -> نتيجة<نص> {
إذا (الاسم يطابق "") {
أرجع إخفاق("empty-name", "name was empty").
}
أرجع نجاح("hello " + الاسم).
}
دالة ابدأ_الرئيسية() -> ص64 {
دع جيد: نتيجة<نص> = حي("aspl").
إذا (جيد::نجاح) {
اطبع(جيد::قيمة).
اطبع(" ").
} وإلا {
أرجع 1.
}
دع سيئ: نتيجة<نص> = حي("").
إذا (سيئ::نجاح) {
أرجع 2.
}
اطبع(سيئ::الخطأ::الرمز).
أرجع 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"
}
}English source
This supplied complete source opens a new draft. Prepare the declared inputs/files in that draft, then select Run explicitly.
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"
}
}Mixed source
This supplied complete source opens a new draft. Prepare the declared inputs/files in that draft, then select Run explicitly.
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) -> نتيجة<string> {
إذا (name matches "") {
return إخفاق("empty-name", "name was empty");
}
return نجاح("hello " + name);
}
fn ابدأ_الرئيسية() -> i64 {
دع good: result<string> = greet("aspl").
if (good::نجاح) {
اطبع(good::value);
print(" ");
} وإلا {
return 1;
}
let bad: نتيجة<string> = greet("");
إذا (bad::ok) {
أرجع 2.
}
print(bad::الخطأ::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"
}
}Check the result
The source cards show the catalog's exact inputs and outcomes. Locale changes do not translate the supplied source. Download retains original source bytes.