diff options
author | Juan J. Martinez <jjm@usebox.net> | 2024-06-18 18:57:14 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2024-06-18 18:57:14 +0100 |
commit | 88781ff50d9c43b79192448254e086af75cfdbd6 (patch) | |
tree | d0b565fbf4e896c4a925ee6bdc6cc6d5262980d9 /examples/fib_tc.fco | |
parent | 1607b9d3d2a3b511b7914828b4ad6533b1767317 (diff) | |
download | funco-main.tar.gz funco-main.zip |
Diffstat (limited to 'examples/fib_tc.fco')
-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 |