From 14814ecbf53760654aab34e0613abf347a54113f Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Thu, 14 Oct 2021 18:06:54 +0200 Subject: Add fun sugar for function variable declaration --- tests/variables_expected.txt | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'tests') diff --git a/tests/variables_expected.txt b/tests/variables_expected.txt index 2e6e2be..02a5f7a 100644 --- a/tests/variables_expected.txt +++ b/tests/variables_expected.txt @@ -1,11 +1,23 @@ -(error? (def a 1)) -> false -a -> 1 -(error? (def a 300)) -> false -a -> 300 -(error? (def a "strings")) -> false -a -> "strings" -(error? (def a 1)) -> false -a -> (:quoted :symbols 123 :or "strings") -(error? (set! a 42)) -> false -a -> 42 -(error? (set! b 99)) -> true +(def a 20) +((lambda (a b) (+ 10 a b)) 1 2) -> 13 +((lambda (a b) (+ 10 a b)) a 3) -> 33 +(def myfun (lambda (a b) (+ a b))) (myfun 6 9) -> 15 +(fun myfun (a b) (+ a b)) (myfun 6 9) -> 15 +(+ 1 (myfun 10 (myfun a a)) 30) -> 81 +(myfun 10 (myfun 5 0)) -> 15 +(fun make-counter () (def value 0) (def counter (lambda () (set! value (+ value 1)) value)) counter) +(def counter-a (make-counter)) +(def counter-b (make-counter)) +(counter-a) -> 1 +(counter-b) -> 1 +(counter-a) -> 2 +(counter-a) -> 3 +(counter-a) -> 4 +(counter-b) -> 2 +(counter-b) -> 3 +(counter-b) -> 4 +(fun fib (n) (if (<= n 2) 1 (+ (fib (- n 1)) (fib (- n 2))))) +(fib 15) -> 610 +(fun b () (display a) (print " --- ") (def a 42) (display a) (newline)) +(b) -> 20 --- 42 +(b) -> 20 --- 42 -- cgit v1.2.1