1 # example program: constructing functions out of order
 2 #
 3 # We construct a factorial function with separate base and recursive cases.
 4 # Compare factorial.mu.
 5 #
 6 # This isn't a very tasteful example, just a simple demonstration of
 7 # possibilities.
 8 
 9 def factorial n:num -> result:num [
10   local-scope
11   load-ingredients
12   {
13     <base-case>
14   }
15   <recursive-case>
16 ]
17 
18 after <base-case> [
19   # if n=0 return 1
20   zero?:bool <- equal n, 0
21   break-unless zero?
22   return 1
23 ]
24 
25 after <recursive-case> [
26   # return n * factorial(n - 1)
27   x:num <- subtract n, 1
28   subresult:num <- factorial x
29   result <- multiply subresult, n
30 ]
31 
32 def main [
33   1:num <- factorial 5
34   # trailing space in next line is to help with syntax highlighting
35   $print [result: ], 1:num, [ 
36 ]
37 ]