Exemplo n.º 1
0
def any(xs):
    if not xs:
        return False
    else:
        x = head(xs)
        if x:
            return True
        return or_(x, any(tail(xs)))
Exemplo n.º 2
0
def all(xs):
    if not xs:
        return True
    else:
        x = head(xs)
        if not x:
            return False
        return and_(x, all(tail(xs)))
Exemplo n.º 3
0
def foldr(f, v, xs):
    if not xs:
        return v
    else:
        return f(head(xs), foldr(f, v, tail(xs)))
Exemplo n.º 4
0
def length(xs):
    if not xs:
        return 0
    else:
        return 1 + length(tail(xs))
Exemplo n.º 5
0
def reduce(f, xs):
    if not xs:
        return 0
    else:
        return f(head(xs), reduce(f, tail(xs)))
Exemplo n.º 6
0
def filter(p, xs):
    if not xs:
        return []
    else:
        return [head(xs)] + filter(p, tail(xs)) if p(head(xs)) else filter(p, tail(xs))
Exemplo n.º 7
0
def map(f, xs):
    if not xs:
        return []
    else:
        return [f(head(xs))] + map(f, tail(xs))
Exemplo n.º 8
0
def reverse(xs):
    if not xs:
        return []
    else:
        return reverse(tail(xs)) + [head(xs)]
Exemplo n.º 9
0
def product(xs):
    if not xs:
        return 1
    else:
        return head(xs) * product(tail(xs))
Exemplo n.º 10
0
def sum(xs):
    if not xs:
        return 0
    else:
        return head(xs) + sum(tail(xs))
Exemplo n.º 11
0
def foldr(f, v, xs):
    if not xs:
        return v
    else:
        return f(head(xs), foldr(f, v, tail(xs)))