Ejemplo n.º 1
0
def IsEmpty(As):
    """ Controlla se As è una lista vuota """
    return As == EmptyList()
Ejemplo n.º 2
0
 def MakeI(n):
     if n > b:
         return EmptyList()
     return MakeList(n, MakeI(n + 1))
Ejemplo n.º 3
0
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))
Ejemplo n.º 4
0
def FoldReverse(Ls):
    """ Reverse in termini di Fold """
    def Concatenate(x, Ls):
        return Append(Ls, MakeList(x))

    return Fold(Concatenate, Ls, EmptyList())
Ejemplo n.º 5
0
def FoldFilter(P, Ls):
    """ Filter in termini di Fold """
    return Fold(lambda x, y: MakeList(x, y) if P(x) else y, Ls, EmptyList())
Ejemplo n.º 6
0
def FoldMap(F, Ls):
    """ Map in termini di Fold """
    return Fold(lambda x, y: MakeList(F(x), y), Ls, EmptyList())
Ejemplo n.º 7
0
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))