red-test for recursive fns
This commit is contained in:
parent
d2ba02cdd9
commit
460b9aa675
2 changed files with 20 additions and 0 deletions
16
examples/recursive-fn.lsh
Normal file
16
examples/recursive-fn.lsh
Normal 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
4
examples/strict-fn.lsh
Normal file
|
@ -0,0 +1,4 @@
|
|||
def foo (fn [x] (* x x))
|
||||
foo 3
|
||||
foo (foo 3)
|
||||
= 81 (foo (foo 3))
|
Loading…
Reference in a new issue