defmacro MAX(x, y) [ ((x) < (y) ? (y) : (x)) ] defmacro fmt(fmt, ...args) [ printf(fmt, args) ] defmacro add { (x) [ (x) ], (x, y, ...rest) [ (x) + add(y, rest) ] } defmacro swap(x, y) [{ let $x = &(x); let $y = &(y); let $z = *($x); *($x) = *($y); *($y) = ($z); }] fn fact(x usize) usize { fn f(acc usize, n usize) usize { return n == 0 ? acc : f(acc * n, n - 1); } return f(1, x); } extern fn main (argc int, argv **u8) int { extern fn printf(fmt *const u8, ...) int; fmt("%d\n", add(1, 2, 3, 4)); let x = 0; let y = 7; printf("x: %d; y: %d\n", x, y); swap(x, y); printf("x: %d; y: %d\n", x, y); printf("fact(6) = %zu\n", fact(6)); fn foo(n int) int { return n + 1; } return foo(-1); }