about summary refs log tree commit diff stats
path: root/tangle.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2017-09-23 18:31:26 -0700
committerKartik K. Agaram <vc@akkartik.com>2017-09-23 18:41:47 -0700
commit72cf994869e19f6bdc4678e1122f0082d07d4a11 (patch)
treee7a39da677884476a3088a96b1dab125d310316d /tangle.mu
parent50685c29bdafaa3fab19c832b421707b0442fdc6 (diff)
downloadmu-72cf994869e19f6bdc4678e1122f0082d07d4a11.tar.gz
4002
Diffstat (limited to 'tangle.mu')
-rw-r--r--tangle.mu25
1 files changed, 12 insertions, 13 deletions
diff --git a/tangle.mu b/tangle.mu
index 4b13c910..e8388a72 100644
--- a/tangle.mu
+++ b/tangle.mu
@@ -3,30 +3,29 @@
 # We construct a factorial function with separate base and recursive cases.
 # Compare factorial.mu.
 #
-# This isn't a very tasteful example, just a simple demonstration of
+# This isn't a very tasteful example, just a basic demonstration of
 # possibilities.
 
 def factorial n:num -> result:num [
   local-scope
   load-ingredients
-  {
-    <base-case>
-  }
-  <recursive-case>
+  <factorial-cases>
 ]
 
-after <base-case> [
+after <factorial-cases> [
   # if n=0 return 1
-  zero?:bool <- equal n, 0
-  break-unless zero?
-  return 1
+  return-unless n, 1
 ]
 
-after <recursive-case> [
+after <factorial-cases> [
   # return n * factorial(n - 1)
-  x:num <- subtract n, 1
-  subresult:num <- factorial x
-  result <- multiply subresult, n
+  {
+    break-unless n
+    x:num <- subtract n, 1
+    subresult:num <- factorial x
+    result <- multiply subresult, n
+    return result
+  }
 ]
 
 def main [