aboutsummaryrefslogtreecommitdiff
path: root/examples/fold.fco
blob: 4cb5b06d5d633867adb3c9d27e34697f9ed42c34 (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 with integers 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 1000
def main()
    display(fold(0 op range(1001)))
end