Exemplo n.º 1
0
def filter_f(p):
    return (
        lambda list_f: Nil
        if nil(list_f)
        else filter_f(p)(tail(list_f))
        if not p(head(list_f))
        else cons(head(list_f))(filter_f(p)(tail(list_f)))
    )
Exemplo n.º 2
0
def eq(lst1):
    return (
        lambda lst2: True
        if nil(lst1)
        and nil(lst2)
        or not nil(lst1)
        and not nil(lst2)
        and head(lst1) == head(lst2)
        and eq(tail(lst1))(tail(lst2))
        else False
    )
Exemplo n.º 3
0
 def inner(lst):
     if nil(lst):
         return False
     elif head(lst) == e:
         return True
     else:
         return elem(e)(tail(lst))
Exemplo n.º 4
0
def unzip_func(list_pairs):
    if nil(list_pairs):
        return pair(Nil)(Nil)
    else:
        tail_unzipped = unzip_func(tail(list_pairs))
        head_pair = head(list_pairs)
        return pair(cons(fst(head_pair))(fst(tail_unzipped)))(
            cons(snd(head_pair))(snd(tail_unzipped))
        )
Exemplo n.º 5
0
def foldr(f):
    return (
        lambda accm: lambda list_f: accm
        if nil(list_f)
        else f(head(list_f))(foldr(f)(accm)(tail(list_f)))
    )
Exemplo n.º 6
0
def map_f(f):
    return lambda list_f: Nil if nil(list_f) else cons(f(head(list_f)))(map_f(f)(tail(list_f)))
Exemplo n.º 7
0
def concat(lst1):
    return lambda lst2: lst2 if nil(lst1) else cons(head(lst1))(concat(tail(lst1))(lst2))
Exemplo n.º 8
0
def take(n):
    return lambda lst: Nil if nil(lst) or n == 0 else cons(head(lst))(take(n - 1)(tail(lst)))
Exemplo n.º 9
0
def last(lst):
    return (lambda t: head(lst) if nil(t) else last(t))(tail(lst))
Exemplo n.º 10
0
def zip_f(a_lst_f):
    return (
        lambda b_lst_f: Nil
        if nil(a_lst_f) or nil(b_lst_f)
        else cons(pair(head(a_lst_f))(head(b_lst_f)))(zip_f(tail(a_lst_f))(tail(b_lst_f)))
    )
Exemplo n.º 11
0
def init(lst):
    return (lambda t: Nil if nil(t) else cons(head(lst))(init(t)))(tail(lst))