1 # example program: compute the factorial of 5
 2 
 3 def main [
 4   local-scope
 5   x:num <- factorial 5
 6   $print [result: ], x, [ 
 7 ]
 8 ]
 9 
10 def factorial n:num -> result:num [
11   local-scope
12   load-ingredients
13   # if n=0 return 1
14   return-unless n, 1
15   # return n * factorial(n-1)
16   x:num <- subtract n, 1
17   subresult:num <- factorial x
18   result <- multiply subresult, n
19 ]
20 
21 # unit test
22 scenario factorial-test [
23   run [
24   ¦ 1:num <- factorial 5
25   ]
26   memory-should-contain [
27   ¦ 1 <- 120
28   ]
29 ]