https://github.com/akkartik/mu1/blob/master/factorial.mu
1
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-inputs
13 {
14
15 zero?:bool <- equal n, 0
16 break-unless zero?
17 return 1
18 }
19
20 x:num <- subtract n, 1
21 subresult:num <- factorial x
22 result <- multiply subresult, n
23 ]
24
25
26 scenario factorial-test [
27 run [
28 1:num <- factorial 5
29 ]
30 memory-should-contain [
31 1 <- 120
32 ]
33 ]