aboutsummaryrefslogtreecommitdiff
path: root/examples/sum.fwd
blob: 89a2d117f680b02267a3e0018f84ded98bb8e040 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
print_int(i64 a);
print_nl();

sum_inner(i64 s, i64 n, (i64) res)
{
	if n <= 0 {
		res(s);
	} else {
		sum_inner(s + n, n - 1, res);
	}
}

sum(i64 n, (i64) res)
{
	sum_inner(0, n, res);
}

main()
{
	sum(1000000000) => i64 s;
	print_int(s);
	print_nl();
}