blob: dc7526d287c5f1be6919ed52dad42df4d114bc07 (
plain)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#include "std/mem.toc", mem;
#include "std/io.toc", io;
use mem;
fill_array ::= fn(n ::=, a : &[n]int) {
for i := 0..n-1 {
a[i] = i*i;
}
a[0] = 17;
}
sum_array ::= fn(n ::=, a : &[n]int) total := 0 {
for i := 0..n-1 {
total += a[i];
}
}
fill_slice ::= fn(a: &[]int) {
*a = mem.news(int, 3);
a[0] = 1;
a[1] = 48;
a[2] = 136;
}
sum_slice ::= fn(a : &[]int) total := 0 {
for i := 0..a.len-1 {
total += a[i];
}
}
thing ::= fn() int {
foo : [5]int;
fill_array(&foo);
a := sum_array(&foo);
bar : []int;
defer dels(bar);
fill_slice(&bar);
b := sum_slice(&bar);
a+b
}
main ::= fn() {
a := thing();
b ::= thing();
io.puti(a);
io.puti(b);
}
|