示例#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)))
    )
示例#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
    )
示例#3
0
 def inner(lst):
     if nil(lst):
         return False
     elif head(lst) == e:
         return True
     else:
         return elem(e)(tail(lst))
示例#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))
        )
示例#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)))
    )
示例#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)))
示例#7
0
def concat(lst1):
    return lambda lst2: lst2 if nil(lst1) else cons(head(lst1))(concat(tail(lst1))(lst2))
示例#8
0
def drop(n):
    return lambda lst: lst if nil(lst) or n == 0 else drop(n - 1)(tail(lst))
示例#9
0
def take(n):
    return lambda lst: Nil if nil(lst) or n == 0 else cons(head(lst))(take(n - 1)(tail(lst)))
示例#10
0
def length(lst):
    return 0 if nil(lst) else 1 + length(tail(lst))
示例#11
0
def last(lst):
    return (lambda t: head(lst) if nil(t) else last(t))(tail(lst))
示例#12
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)))
    )
示例#13
0
def init(lst):
    return (lambda t: Nil if nil(t) else cons(head(lst))(init(t)))(tail(lst))