Initial Commit
This commit is contained in:
782 files changed
+145156
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import std::io;
|
||||
trait Show { def show(&this): i64; }
|
||||
def i64::show(&this): i64 { return this * 10; }
|
||||
def bool::show(&this): i64 { return this == true ? 1 : 0; }
|
||||
def total<Ts...>(args: Ts...): i64 where Ts...: Show {
|
||||
var t: i64 = 0;
|
||||
for const x in args { t += x.show(); }
|
||||
return t;
|
||||
}
|
||||
def count<Ts...>(args: Ts...): u64 { return args.length; }
|
||||
def known<Ts...>(args: Ts...): i64 {
|
||||
var t: i64 = 0;
|
||||
for const x in args { continue if const !(x is Show); t += 1; }
|
||||
return t;
|
||||
}
|
||||
def pair<Ts...>(args: Ts...): i64 where Ts...: integer { return (args[0] + args[1]) as i64; }
|
||||
def forward<Ts...>(args: Ts...): i64 where Ts...: Show { return total(...args); }
|
||||
def add3(a: i64, b: i64, c: i64): i64 { return a + b + c; }
|
||||
def spread<Ts...>(args: Ts...): i64 { return add3(...args); }
|
||||
def sum<T, Ts...>(first: T, rest: Ts...): T where T: numeric where Ts...: numeric {
|
||||
return first if const rest.length == 0;
|
||||
return first + sum(...rest) as T;
|
||||
}
|
||||
def until<Ts...>(args: Ts...): u64 {
|
||||
var n: u64 = 0;
|
||||
for const x in args { break if const !(x is Show); n++; }
|
||||
return n;
|
||||
}
|
||||
def bump<Ts...>(args: Ts...): i64 where Ts...: integer {
|
||||
for const x in args { x += 1; }
|
||||
return args[0] as i64;
|
||||
}
|
||||
const three := count(1, 2, 3);
|
||||
def main(): void {
|
||||
println($"{total(1, true, 2)} {count()} {three} {known(1, 2.5, true)} {pair(3, 4)}");
|
||||
println($"{forward(5, false)} {spread(1, 2, 3)} {sum(1, 2, 3.5)} {until(1, true, 2.5, 3)} {bump(9)}");
|
||||
}
|
||||
Reference in new issue
Block a user