diff options
-rw-r--r-- | examples/fib_tc.fco | 19 |
1 files changed, 19 insertions, 0 deletions
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 |