aboutsummaryrefslogtreecommitdiff
path: root/examples/fold.fco
blob: 97b6de89d338b9cf01f2abfb2d1eb4a09d8113dd (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-1
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