import std::io; type op = def(i64, i64): i64; def add(a: i64, b: i64): i64 { return a + b; } def mul(a: i64, b: i64): i64 { return a * b; } def twice(x: T): T where T: numeric { return x + x; } struct entry { val name: span; val run: op; } const ops: entry[3] = [entry{ name = "add", run = add }, entry{ name = "mul", run = mul }, entry{ name = "sub", run = def(a: i64, b: i64): i64 { return a - b; } }]; const dbl: def(i64): i64 = twice::; def made(): span { val table := raw_allocate(2 * size_of::()) as *mut op; table[0] = mul; table[1] = add; return table[0:2]; } const kept: span = made(); def main(): void { for &e in ops { print($"{e.name}={e.run(6, 3)} "); } println($"{dbl(21)} {kept[0](4, 5)} {kept[1](4, 5)} {ops[1].run}"); }