loom
16 строк · 344.0 Байт
1import "Exception" type Exception
2
3// Module interface declaration
4interface Factorial : immutable, throw (Exception) {
5pure factorial(int n) -> int
6}
7
8// Defining module functions
9pure factorial(int n)
10-> int
11{
12if (n <= 0)
13throw Exception("factorial", "Invalid argument value")
14
15return (n == 1) ? 1 : n*factorial(n-1)
16}
17
18