vile / examples / alt / functions.vile
32 lines · 29 sloc · 486 bytes · 76646891b77a3d5c6af4a1e42b122cd61dc1654b
Raw
1hypotenuse(a, b) := {
2 aa := a * a
3 bb := b * b
4 sqrt(aa + bb)
5}
6
7make-counter(start) := {
8 count := start
9 fn() {
10 count = count + 1
11 count
12 }
13}
14
15stats(xs) := {
16 n := vector-length(xs)
17 total := 0
18 i := 0
19 while i < n {
20 total = total + xs[i]
21 i = i + 1
22 }
23 [n, total, if n == 0 { 0 } else { total / n }]
24}
25
26display(hypotenuse(3, 4))
27newline()
28counter := make-counter(10)
29display([counter(), counter(), counter()])
30newline()
31display(stats([2, 4, 6]))
32newline()
33