f2b86b8a3ed6c569eb0cc53989cb8cec065b4399
[cc1516.git] / examples / test.spl
1 map(f, l){
2 if(isEmpty(l)){
3 return [];
4 } else {
5 return f(l.hd) : map(f, l.tl);
6 }
7 }
8
9 plus(x, y){
10 return x + y;
11 }
12
13 foldr(f, acc, l){
14 if(isEmpty(l)){
15 return acc;
16 } else {
17 return foldr(f, f(acc, l.hd), l.tl);
18 }
19 }
20
21 times(x, y){
22 return x * y;
23 }
24
25 main(){
26 [Int] l1 = 1 : 2 : 3 : 4 : 5 : [];
27 foldr(times, 1, l1);
28 print("faculty of 5 is: ");
29 print(foldr(times, 1, l1));
30 }