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 basic demonstration of 7 # possibilities. 8 9 def factorial n:num -> result:num [ 10 local-scope 11 load-inputs 12 <factorial-cases> 13 ] 14 15 after <factorial-cases> [ 16 # if n=0 return 1 17 return-unless n, 1 18 ] 19 20 after <factorial-cases> [ 21 # return n * factorial(n - 1) 22 { 23 ¦ break-unless n 24 ¦ x:num <- subtract n, 1 25 ¦ subresult:num <- factorial x 26 ¦ result <- multiply subresult, n 27 ¦ return result 28 } 29 ] 30 31 def main [ 32 1:num <- factorial 5 33 # trailing space in next line is to help with syntax highlighting 34 $print [result: ], 1:num, [ 35 ] 36 ]