Add a 'tail recursive' fibonacci program

This commit is contained in:
Danila Fedorin 2019-08-17 23:09:30 -07:00
parent 03581f7af0
commit bca70ce2a0

14
programs/fib.lily Normal file
View File

@ -0,0 +1,14 @@
defn if c t e = {
case c of {
True -> { t }
False -> { e }
}
}
defn fibtr a b n = {
if (eq n 0) a (fibtr b (a+b) (n-1))
}
defn fib n = { fibtr 1 1 n }
defn main = { fib 40 }