aboutsummaryrefslogtreecommitdiff
path: root/examples/fib_tc.fco
blob: b23175149d4ad3bdcd5cdccb75c809c1c91864d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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