progs/fact.fun
changeset 655 3d04ee04966d
parent 626 2d91b2107656
child 702 39e21a33ffb0
--- a/progs/fact.fun	Sun Oct 13 00:53:20 2019 +0100
+++ b/progs/fact.fun	Mon Oct 14 00:02:24 2019 +0100
@@ -1,8 +1,17 @@
-def fact(n) = if n == 0 then 1 else n * fact(n - 1);
+// a simple factorial program
+// (including a tail recursive version)
 
-def facT(n, acc) = if n == 0 then acc else facT(n - 1, n * acc);
+
+def fact(n) =
+  if n == 0 then 1 else n * fact(n - 1);
 
-facT(15, 1)
+def facT(n, acc) =
+  if n == 0 then acc else facT(n - 1, n * acc);
+
+def facTi(n) = facT(n, 1);
 
-//fact(15)
+//fact(10)
+//facTi(10)
 
+write(facTi(5 + 5))
+