1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
printf ::= #foreign("printf","libc.so.6") fn(#C &"const char", #C ..) #C int;
tprintf ::= fn(fmt: []char, args: ..) {
printf(&fmt[0], args);
};
sum ::= fn(x: ..) int {
total := 0;
for a, i := x {
total += a + i - i + 1;
}
return total - x.len;
};
sumc ::= fn(x:: ..) int {
total := 0;
for a, i := x {
total += a + i - i + 1;
}
return total - x.len;
};
do_printing ::= fn(x::..) {
tprintf("%ld\n",sum(x));
tprintf("%ld\n",sumc(x));
};
main ::= fn() {
do_printing();
do_printing(1,2,3);
do_printing(4);
do_printing(1,10,100,1000,10000);
};
|