red-test for recursive fns

This commit is contained in:
Yann Esposito (Yogsototh) 2017-04-09 18:09:31 +02:00
parent d2ba02cdd9
commit 460b9aa675
Signed by untrusted user who does not match committer: yogsototh
GPG key ID: 7B19A4C650D59646
2 changed files with 20 additions and 0 deletions

16
examples/recursive-fn.lsh Normal file
View file

@ -0,0 +1,16 @@
def fact (fn [n] (if (<= n 1) 1 (* (fact (- n 1)) n)))
= 1 (fact 0)
= 1 (fact 1)
= 2 (fact 2)
= 6 (fact 3)
= 24 (fact 4)
= 120 (fact 5)
def fib (fn [n] (if (<= n 1) 1 (+ (fib (- n 2)) (fib (- n 1)))))
= 1 (fib 0)
= 1 (fib 1)
= 2 (fib 2)
= 3 (fib 3)
= 5 (fib 4)
= 8 (fib 5)
= 13 (fib 6)
= 21 (fib 7)

4
examples/strict-fn.lsh Normal file
View file

@ -0,0 +1,4 @@
def foo (fn [x] (* x x))
foo 3
foo (foo 3)
= 81 (foo (foo 3))