diff --git a/functional_tests/hello-world.at b/functional_tests/hello-world.at deleted file mode 100644 index a9051eb..0000000 --- a/functional_tests/hello-world.at +++ /dev/null @@ -1,5 +0,0 @@ -=== script === -print "Hello World!" - -=== output === -Hello World! diff --git a/functional_tests/recursive-faculty.at b/functional_tests/recursive-faculty.at deleted file mode 100644 index e3a19d4..0000000 --- a/functional_tests/recursive-faculty.at +++ /dev/null @@ -1,10 +0,0 @@ -=== script === -fac = { - 0 -> 1 - n -> * n (fac (--n )) -} - -print (fac 10) - -=== output === -3628800 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d6c7d3f..cf9e75b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -53,6 +53,12 @@ function(functionaltest name) endfunction() functionaltest("hello-world") +functionaltest("factorial") +functionaltest("function-const-capture") +functionaltest("function-mutable-capture") +functionaltest("map") +functionaltest("deconstruct") +functionaltest("shadowing") install(TARGETS apfl DESTINATION lib) install(TARGETS apfl-bin DESTINATION bin) diff --git a/src/functional-tests/deconstruct.at b/src/functional-tests/deconstruct.at new file mode 100644 index 0000000..41be8fa --- /dev/null +++ b/src/functional-tests/deconstruct.at @@ -0,0 +1,19 @@ +===== script ===== +[a 1 "Hello" b [_ ~c] d e] = [0 1 "Hello" "world" [1 2 3 4 5] true nil] +print a +print b +print c +print d +print e + +===== output ===== +0 +world +[ + 2 + 3 + 4 + 5 +] +true +nil diff --git a/src/functional-tests/factorial.at b/src/functional-tests/factorial.at new file mode 100644 index 0000000..ea81601 --- /dev/null +++ b/src/functional-tests/factorial.at @@ -0,0 +1,10 @@ +===== script ===== +fac := { +0 -> 1 +n -> * n (fac (- n 1)) +} + +print (fac 10) + +===== output ===== +3628800 diff --git a/functional_tests/function-const-capture.at b/src/functional-tests/function-const-capture.at similarity index 74% rename from functional_tests/function-const-capture.at rename to src/functional-tests/function-const-capture.at index 459538e..5c99b71 100644 --- a/functional_tests/function-const-capture.at +++ b/src/functional-tests/function-const-capture.at @@ -1,4 +1,4 @@ -=== script === +===== script ===== adder = { a -> { b -> + a b } } @@ -9,6 +9,6 @@ inc = adder 1 print (add10 32) print (inc 665) -=== output === +===== output ===== 42 666 diff --git a/functional_tests/function-mutable-capture.at b/src/functional-tests/function-mutable-capture.at similarity index 72% rename from functional_tests/function-mutable-capture.at rename to src/functional-tests/function-mutable-capture.at index 3bef946..81168e1 100644 --- a/functional_tests/function-mutable-capture.at +++ b/src/functional-tests/function-mutable-capture.at @@ -1,7 +1,7 @@ -=== script === +===== script ===== counter = { i = 0 - { i = i + 1 } + { i = + i 1 } } c1 = (counter) @@ -15,7 +15,7 @@ print (c2) print (c1) print (c2) -=== output === +===== output ===== 1 1 2 diff --git a/src/functional-tests/map.at b/src/functional-tests/map.at new file mode 100644 index 0000000..19ade68 --- /dev/null +++ b/src/functional-tests/map.at @@ -0,0 +1,14 @@ +===== script ===== +map := { +_ [] -> [] +f [x ~xs] -> [(f x) ~(map f xs)] +} + +print (map {x -> + x 1} [1 2 3]) + +===== output ===== +[ + 2 + 3 + 4 +] diff --git a/src/functional-tests/shadowing.at b/src/functional-tests/shadowing.at new file mode 100644 index 0000000..7ec78f2 --- /dev/null +++ b/src/functional-tests/shadowing.at @@ -0,0 +1,22 @@ +===== script ===== +foo := 1 +bar := 1 +({ + foo = 2 + bar := 2 + + print "Inside:" + print foo + print bar +}) +print "Outside:" +print foo +print bar + +===== output ===== +Inside: +2 +2 +Outside: +2 +1