1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
#!/usr/bin/env osh
.LANGUAGE: program
errors = false
check(exp, e, r) =
if e = r
println($"$(exp) = $e [SUCCESS]")
else
eprintln($"$(exp) = $e, should be $r [FAILURE]")
errors = true
export
export
################################################
# Factorial
#
fact(i) =
if i = 0
value 1
else
value i * fact(i - 1)
check($"fact(10)", fact(10), 3628800)
################################################
# Mapper
#
map(f, l) =
public.l = l
items[] =
while l.is-nonempty
items[] += f(l[0])
l = nth-tl(1, l)
value items
check($"map(i => i + 1, [10; 20; 30])", map(i => i + 1, [10; 20; 30]), [11; 21; 31])
if errors
exit 1
|