aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorEdvard Thörnros <edvard.thornros@gmail.com>2021-01-13 16:21:59 +0100
committerEdvard Thörnros <edvard.thornros@gmail.com>2021-01-14 19:49:06 +0100
commit4a6643964278aa67f0dbaf1ce28eabf46e5785e5 (patch)
treea303dcdfc2986dfd671c6a76ae3194f146dce03d /tests
parent92f18d8f4278a6e6322c4162f78494762ba7cbb6 (diff)
downloadsylt-4a6643964278aa67f0dbaf1ce28eabf46e5785e5.tar.gz
Add functions
Diffstat (limited to 'tests')
-rw-r--r--tests/fun.tdy41
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