progs/fun-tests/fact.fun
author Christian Urban <christian.urban@kcl.ac.uk>
Fri, 22 Jan 2021 10:39:04 +0000
changeset 822 6b06aeb192ea
parent 790 31a9f89776a3
permissions -rw-r--r--
updated

def fact(n) =
  (if n == 0 then 1 else n * fact(n - 1));

def facT(n, acc) =
  if n == 0 then acc else facT(n - 1, n * acc);

def facTi(n) = facT(n, 1);

//fact(10)
//facTi(10)

write(facTi(6))

// a simple factorial program
// (including a tail recursive version)