aboutsummaryrefslogtreecommitdiff
path: root/examples/fold.fco
blob: c9b8e5c55f4883266eb6a9af3a4c848fb058f29b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
def op(acc x)
    if mod(x 2)
        +(acc x)
    else
        acc
    end
end

# generate a list from 1 to n
def range(n)
    def genrec(l limit n)
        if <(n limit)
            @genrec(+(l list(n)) limit +(n 1))
        else
            l
        end
    end
    genrec(list() n 0)
end

# add odd numbers from 0 to 1001
def main()
    display(fold(0 op range(1001)))
end