Factorial in E

Example for versions E-on-Java 0.9.3

E is implicitly-typed language; :int in function signature is not a type declaration but rather a “guard” — a contract which guarantees that factorial function will be given only integer arguments and it will return only integer values. Such limitations are not necessary but quite useful for code auditing.

def factorial(n :int) :int {
  if (n == 0) {
    return 1
  } else {
    return n * factorial(n-1)
  }
} 

for n in 0..16 {
  println(n.toString(10) + "! = " + factorial(n).toString(10))
}