From 88781ff50d9c43b79192448254e086af75cfdbd6 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Tue, 18 Jun 2024 18:57:14 +0100 Subject: Fibonacci number with tail call optimization --- examples/fib_tc.fco | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 examples/fib_tc.fco diff --git a/examples/fib_tc.fco b/examples/fib_tc.fco new file mode 100644 index 0000000..b231751 --- /dev/null +++ b/examples/fib_tc.fco @@ -0,0 +1,19 @@ +# fibonacci number with tail call optimization +def fib(n) + def fibrec(n acc1 acc2) + if =(n 0) + acc1 + elif =(n 1) + acc2 + else + @fibrec(-(n 1) acc2 +(acc1 acc2)) + end + end + + fibrec(90 0 1) +end + +def main() + display("Running fib(90)...") + display(fib(90)) +end -- cgit v1.2.3