progs/fun/fact.fun
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Mon, 20 Jul 2020 10:06:43 +0100
changeset 735 fc2e3609d5e5
parent 702 progs/fact.fun@39e21a33ffb0
child 814 1fbaa5f05516
permissions -rw-r--r--
updatd

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)