def IsEmpty(As): """ Controlla se As è una lista vuota """ return As == EmptyList()
def MakeI(n): if n > b: return EmptyList() return MakeList(n, MakeI(n + 1))
def SplitList(Ls, end, start=0): """ Ritorna gli elementi da start a end-1""" if start >= end: return EmptyList() return MakeList(Nth(Ls, start), SplitList(Ls, end, start + 1))
def FoldReverse(Ls): """ Reverse in termini di Fold """ def Concatenate(x, Ls): return Append(Ls, MakeList(x)) return Fold(Concatenate, Ls, EmptyList())
def FoldFilter(P, Ls): """ Filter in termini di Fold """ return Fold(lambda x, y: MakeList(x, y) if P(x) else y, Ls, EmptyList())
def FoldMap(F, Ls): """ Map in termini di Fold """ return Fold(lambda x, y: MakeList(F(x), y), Ls, EmptyList())
def MakeRandomInts(n, a, b): """ Restituisce una lista n di numeri causali, uniformente distribuiti nell'intervallo [a,b] (estremi compresi) """ if n == 0: return EmptyList() return MakeList(randint(a, b), MakeRandomInts(n - 1, a, b))