aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-01-21 20:59:38 +0100
committerGustav Sörnäs <gustav@sornas.net>2021-01-21 20:59:38 +0100
commitca1a394cca0c88b7656d156c9ba68bd9468a6612 (patch)
treefc6ec74eabfb0950fc275676815c0e72474737ab /src/lib.rs
parent9e77bcebae382b5b5f712d87328b56129ccfe890 (diff)
parent4448657f8443842e3ef75353c5fa87dfebb3cffd (diff)
downloadsylt-ca1a394cca0c88b7656d156c9ba68bd9468a6612.tar.gz
Merge remote-tracking branch 'origin/wip-close' into main
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs52
1 files changed, 50 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 82905de..e83d11f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -169,7 +169,7 @@ mod tests {
simplest: "f := fn {}
f()",
param_1: "f := fn a: int {}
- f(1)",
+ f(1)",
return_1: "f := fn -> int {
ret 1
}
@@ -222,7 +222,55 @@ mod tests {
}
1 + f(2, 3) <=> 6
2 * f(2, 3) <=> 10
- f(2, 3) - (2 + 3) <=> 0"
+ f(2, 3) - (2 + 3) <=> 0",
+ factorial: "factorial : fn int -> int = fn n: int -> int {
+ if n <= 1 {
+ ret 1
+ }
+ ret n * factorial(n - 1)
+ }
+ factorial(5) <=> 120
+ factorial(6) <=> 720
+ factorial(12) <=> 479001600",
+
+ returning_closures: "
+f : fn -> fn -> int = fn -> fn -> int {
+ x : int = 0
+ f := fn -> int {
+ x = x + 1
+ ret x
+ }
+ f() <=> 1
+ ret f
+}
+
+a := f()
+b := f()
+
+a() <=> 2
+a() <=> 3
+
+b() <=> 2
+b() <=> 3
+
+a() <=> 4
+"
+
+ //TODO this tests doesn't terminate in proper time if we print blocks and ops
+ /*
+ fibonacci: "fibonacci : fn int -> int = fn n: int -> int {
+ if n == 0 {
+ ret 0
+ } else if n == 1 {
+ ret 1
+ } else if n < 0 {
+ <!>
+ }
+ ret fibonacci(n - 1) + fibonacci(n - 2)
+ }
+ fibonacci(10) <=> 55
+ fibonacci(20) <=> 6765"
+ */
);
test_file!(scoping, "tests/scoping.tdy");