Initial Commit
This commit is contained in:
706 files changed
+135430
No files matched your search
@@ -0,0 +1,25 @@
|
||||
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")}");
|
||||
}
|
||||
Reference in new issue
Block a user