Add a 'tail recursive' fibonacci program
This commit is contained in:
parent
03581f7af0
commit
bca70ce2a0
14
programs/fib.lily
Normal file
14
programs/fib.lily
Normal 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 }
|
Loading…
Reference in New Issue
Block a user