Files

25 lines
927 B
Plaintext
Raw Permalink Normal View History

2026-10-26 10:14:11 -05:00
import std::io;
struct failure { val message: span<u8>; }
union result<T> { var value: T; var failure: failure; }
union shape { var none: bool; var size: f64; var name: span<u8>; var names: span<span<u8>>; }
def parse(text: span<u8>): result<int> {
if text.length == 0 { return failure{ "empty" }; }
return text.length as int;
}
def show(r: result<int>): string {
return match r { value(v) => $"{v}", failure(f) => f.message };
}
def wrap<T>(x: T): result<T> { return x; }
def main(): void {
var s: shape = 1.5;
print($"{s} ");
s = "box";
print($"{s} ");
val two: span<u8>[2] = ["a", "b"];
s = span::<span<u8>>::over((&two) as *span<u8>, 2);
println($"{s}");
val all: shape[3] = [true, 2.5, "c"];
val t: shape = all.length > 5 ? "big" : 0.5;
val m: shape = match all.length { 3 => "three", else => false };
println($"{all} {t} {m} {show(parse("abc"))} {show(parse(""))} {wrap::<span<u8>>("w")}");
}