Man or boy test
editable example
Click the pencil to open this in an editor, change it, and run it in your browser. The same solution is posted on Rosetta Code.
ghul
use IO.Std.write_line
a(
k: int,
x1: () -> int,
x2: () -> int,
x3: () -> int,
x4: () -> int,
x5: () -> int
) -> int is
let counter mut = k
let b = () rec => (
counter = counter - 1
a(counter, rec, x1, x2, x3, x4)
)
return if counter <= 0 then x4() + x5() else b() fi
si
for k in 0::10 do
let result = a(k, () => 1, () => -1, () => -1, () => 1, () => 0)
write_line("k = {k,2}: {result}")
od