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