progs/fact.fun
author Christian Urban <urbanc@in.tum.de>
Mon, 18 Nov 2019 11:11:11 +0000
changeset 694 b6ed836ce59b
parent 655 3d04ee04966d
child 702 39e21a33ffb0
permissions -rw-r--r--
updated

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


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(5 + 5))