progs/fun-tests/fact.fun
changeset 790 71ef7d9ef635
parent 742 155426396b5f
equal deleted inserted replaced
789:966c9fd84693 790:71ef7d9ef635
     1 // a simple factorial program
       
     2 // (including a tail recursive version)
       
     3 
       
     4 
       
     5 def fact(n) =
     1 def fact(n) =
     6   if n == 0 then 1 else n * fact(n - 1);
     2   (if n == 0 then 1 else n * fact(n - 1));
     7 
     3 
     8 def facT(n, acc) =
     4 def facT(n, acc) =
     9   if n == 0 then acc else facT(n - 1, n * acc);
     5   if n == 0 then acc else facT(n - 1, n * acc);
    10 
     6 
    11 def facTi(n) = facT(n, 1);
     7 def facTi(n) = facT(n, 1);
    13 //fact(10)
     9 //fact(10)
    14 //facTi(10)
    10 //facTi(10)
    15 
    11 
    16 write(facTi(6))
    12 write(facTi(6))
    17 
    13 
       
    14 // a simple factorial program
       
    15 // (including a tail recursive version)