aboutsummaryrefslogtreecommitdiffstats
path: root/tests/fun.tdy
blob: 8dc3b77e070e84bac2d23b7de4cd6863bbb1cc7b (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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Simplest
f := fn {
    print 1
}
f()

// Simple
f2 := fn a: int {
    print a
}
f2(2)

// Return value
f3 := fn -> int {
    ret 3
}
print f3()
f3() <=> 3

// Empty function
f4 := fn {}
print f4
print f4()

// Multiple arguments
adder := fn a: int, b: int -> int {
    ret a + b
}
adder(1, 2) <=> 3

// Passing functions
h := fn {
    print "h"
    ret 1
}

g := fn f: int {
    ret f()
}

g(h) <=> 1


q := fn i: int -> int {
    if i == 1 {
        ret 2
    } else {
        ret 3
    }
}

q(1) <=> 2
q(0) <=> 3