diff options
| author | Edvard Thörnros <edvard.thornros@gmail.com> | 2021-01-13 16:21:59 +0100 |
|---|---|---|
| committer | Edvard Thörnros <edvard.thornros@gmail.com> | 2021-01-14 19:49:06 +0100 |
| commit | 4a6643964278aa67f0dbaf1ce28eabf46e5785e5 (patch) | |
| tree | a303dcdfc2986dfd671c6a76ae3194f146dce03d /tests | |
| parent | 92f18d8f4278a6e6322c4162f78494762ba7cbb6 (diff) | |
| download | sylt-4a6643964278aa67f0dbaf1ce28eabf46e5785e5.tar.gz | |
Add functions
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/fun.tdy | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/fun.tdy b/tests/fun.tdy new file mode 100644 index 0000000..8b94cad --- /dev/null +++ b/tests/fun.tdy @@ -0,0 +1,41 @@ +// Simplest +f := fn { + print 1 +} +f() <=> true + +// Simple +f2 := fn a: int { + print a +} +f2(2) <=> true + +// 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 |
