From bca70ce2a0fbffbae1ef148600ae5209837c551b Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sat, 17 Aug 2019 23:09:30 -0700 Subject: [PATCH] Add a 'tail recursive' fibonacci program --- programs/fib.lily | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 programs/fib.lily diff --git a/programs/fib.lily b/programs/fib.lily new file mode 100644 index 0000000..db857f3 --- /dev/null +++ b/programs/fib.lily @@ -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 }