Beispiel #1
0
def div(a, b, lv):
    e = Echo("div", lv)
    e.ask("What's the result of {0} / {1}?".format(to_string(a), to_string(b)))
    if b == 0:
        raise ZeroDivisionError
    e.answer("{0}.".format(a / b))
    return a / b
Beispiel #2
0
def div(a, b, lv):
    e = Echo("div", lv)
    e.ask("What's the result of {0} / {1}?".format(to_string(a), to_string(b)))
    if b == 0:
        raise ZeroDivisionError
    e.answer("{0}.".format(a/b))
    return a/b
Beispiel #3
0
def map_(f, lat, lv):
    e = Echo("map", lv)
    e.ask("What's the result of mapping {0} to each element of {1}".format(to_string(f), to_string(lat)))
    retval = []
    for one in lat:
        retval.append(f(one, lv))
    e.answer("It's {0}".format(to_string(retval)))
    return retval
Beispiel #4
0
def cons(x, y, lv):
    e = Echo("cons", lv)
    e.ask("What's cons of {0} and {1}?".format(to_string(x), to_string(y)))
    if isa(y, list):
        e.answer("{0}.".format(to_string([x]+y)))
        return [x]+y
    else: 
        e.answer("No answer, since the second argument to cons must be list.")
        return None
Beispiel #5
0
def cons(x, y, lv):
    e = Echo("cons", lv)
    e.ask("What's cons of {0} and {1}?".format(to_string(x), to_string(y)))
    if isa(y, list):
        e.answer("{0}.".format(to_string([x] + y)))
        return [x] + y
    else:
        e.answer("No answer, since the second argument to cons must be list.")
        return None
Beispiel #6
0
def is_null(s, lv):
    e = Echo("null?", lv)
    e.ask("Is {0} an empty list?".format(to_string(s)))
    if isa(s, list):
        e.answer("Yes.") if s==[] else e.answer("Nope.")
        return s==[]
    else: 
        e.answer("No answer since you can only ask null? of a list")
        return None
Beispiel #7
0
def is_eq(a, b, lv):
    e = Echo("eq?", lv)
    e.ask("Does {0} eq to {1}?".format(to_string(a), to_string(b)))
    if isa(a, str) and isa(b, str):
        e.answer("Yes.") if a==b else e.answer("Nope.")
        return a==b
    else:
        e.answer("No answer because eq? only accepts two non-numeric atoms.")
        return None
Beispiel #8
0
def is_member(a, lat, lv):
    e = Echo("member?", lv)
    e.ask("Is {0} a member of {1}?".format(to_string(a), to_string(lat)))
    for atom in lat:
        if a == atom:
            e.answer("Yes.")
            return True
    e.answer("Nope.")
    return False
Beispiel #9
0
def map_(f, lat, lv):
    e = Echo("map", lv)
    e.ask("What's the result of mapping {0} to each element of {1}".format(
        to_string(f), to_string(lat)))
    retval = []
    for one in lat:
        retval.append(f(one, lv))
    e.answer("It's {0}".format(to_string(retval)))
    return retval
Beispiel #10
0
def is_number(s, lv):
    e = Echo("number?", lv)
    e.ask("Is {0} number?".format(to_string(s)))
    if isa(s, int) or isa(s, float):
        e.answer("Yes.")
        return True
    else:
        e.answer("Nope.")
        return False
Beispiel #11
0
def is_number(s, lv):
    e = Echo("number?", lv)
    e.ask("Is {0} number?".format(to_string(s)))
    if isa(s, int) or isa(s, float):
        e.answer("Yes.")
        return True
    else:
        e.answer("Nope.")
        return False
Beispiel #12
0
def is_null(s, lv):
    e = Echo("null?", lv)
    e.ask("Is {0} an empty list?".format(to_string(s)))
    if isa(s, list):
        e.answer("Yes.") if s == [] else e.answer("Nope.")
        return s == []
    else:
        e.answer("No answer since you can only ask null? of a list")
        return None
Beispiel #13
0
def is_member(a, lat, lv):
    e = Echo("member?", lv)
    e.ask("Is {0} a member of {1}?".format(to_string(a), to_string(lat)))
    for atom in lat:
        if a == atom:
            e.answer("Yes.")
            return True
    e.answer("Nope.")
    return False
Beispiel #14
0
def is_eq(a, b, lv):
    e = Echo("eq?", lv)
    e.ask("Does {0} eq to {1}?".format(to_string(a), to_string(b)))
    if isa(a, str) and isa(b, str):
        e.answer("Yes.") if a == b else e.answer("Nope.")
        return a == b
    else:
        e.answer("No answer because eq? only accepts two non-numeric atoms.")
        return None
Beispiel #15
0
def is_zero(n, lv):
    e = Echo("zero?", lv)
    e.ask("Is {0} zero?".format(to_string(n)))
    if isa(n, int) or isa(n, float):
        e.answer("Yes.") if n == 0 else e.answer("Nope.")
        if n == 0: return True
        else: return False
    else:
        e.answer("No answer since you can only ask zero? of a number")
        return None
Beispiel #16
0
def is_zero(n, lv):
    e = Echo("zero?", lv)
    e.ask("Is {0} zero?".format(to_string(n)))
    if isa(n, int) or isa(n, float):
        e.answer("Yes.") if n==0 else e.answer("Nope.")
        if n==0: return True
        else: return False
    else:
        e.answer("No answer since you can only ask zero? of a number")
        return None
Beispiel #17
0
def car(x, lv, verbose=False):
    e = Echo("car", lv)
    e.ask("What's car of {0}?".format(to_string(x)))
    if isa(x, str):
        e.answer("No answer, because you cannot ask for the car of an atom.")
        return None
    elif isa(x, list):
        if x == []:
            e.answer("No answer, because you cannot ask for the car of the empty list.")
            return None
        else:
            e.answer("{0}.".format(to_string(x[0])))
            return x[0]
    else:
         e.answer("No answer, because car is only for non-empty lists.")
         return None
Beispiel #18
0
def cdr(x, lv):
    e = Echo("cdr", lv)
    e.ask("What's cdr of {0}?".format(to_string(x)))
    if isa(x, str):
        e.answer("No answer, since you cannot ask for the cdr of an atom.")
        return None
    elif isa(x, list):
        if x == []:
            e.answer("No answer, since you cannot ask for the cdr of the empty list.")
            return None
        else:
            e.answer("{0}.".format(to_string(x[1:])))
            return x[1:]
    else:
        e.answer("No answer, because cdr is only for non-empty lists.")
        return None
Beispiel #19
0
def cdr(x, lv):
    e = Echo("cdr", lv)
    e.ask("What's cdr of {0}?".format(to_string(x)))
    if isa(x, str):
        e.answer("No answer, since you cannot ask for the cdr of an atom.")
        return None
    elif isa(x, list):
        if x == []:
            e.answer(
                "No answer, since you cannot ask for the cdr of the empty list."
            )
            return None
        else:
            e.answer("{0}.".format(to_string(x[1:])))
            return x[1:]
    else:
        e.answer("No answer, because cdr is only for non-empty lists.")
        return None
Beispiel #20
0
def car(x, lv, verbose=False):
    e = Echo("car", lv)
    e.ask("What's car of {0}?".format(to_string(x)))
    if isa(x, str):
        e.answer("No answer, because you cannot ask for the car of an atom.")
        return None
    elif isa(x, list):
        if x == []:
            e.answer(
                "No answer, because you cannot ask for the car of the empty list."
            )
            return None
        else:
            e.answer("{0}.".format(to_string(x[0])))
            return x[0]
    else:
        e.answer("No answer, because car is only for non-empty lists.")
        return None
Beispiel #21
0
def is_atom(s, lv):
    e = Echo("atom?", lv)
    e.ask("Is {0} an atom?".format(to_string(s)))
    e.answer("Yes.") if isa(s, str) or isa(s, int) or isa(s, float) else e.answer("Nope.")
    return isa(s, str) or isa(s, int) or isa(s, float)
Beispiel #22
0
def is_equal(a, b, lv):
    e = Echo("equal?", lv)
    e.ask("Does {0} equal to {1}?".format(to_string(a), to_string(b)))
    e.answer("Yes.") if a==b else e.answer("Nope.")
    return a==b
Beispiel #23
0
def mult(a, b, lv):
    e = Echo("mult", lv)
    e.ask("What's the result of {0} * {1}?".format(to_string(a), to_string(b)))
    e.answer("{0}.".format(a * b))
    return a * b
Beispiel #24
0
def sub1(n, lv):
    e = Echo("sub1", lv)
    e.ask("What is the result of subtracting 1 from {0}?".format(to_string(n)))
    e.answer("{0}.".format(n - 1))
    return n - 1
Beispiel #25
0
def sub(a, b, lv):
    e = Echo("sub", lv)
    e.ask("What's the result of {0} - {1}?".format(to_string(a), to_string(b)))
    e.answer("{0}.".format(a-b))
    return a-b
Beispiel #26
0
def is_equal(a, b, lv):
    e = Echo("equal?", lv)
    e.ask("Does {0} equal to {1}?".format(to_string(a), to_string(b)))
    e.answer("Yes.") if a == b else e.answer("Nope.")
    return a == b
Beispiel #27
0
def is_atom(s, lv):
    e = Echo("atom?", lv)
    e.ask("Is {0} an atom?".format(to_string(s)))
    e.answer("Yes.") if isa(s, str) or isa(s, int) or isa(
        s, float) else e.answer("Nope.")
    return isa(s, str) or isa(s, int) or isa(s, float)
Beispiel #28
0
def not_(s, lv):
    e = Echo("not", lv)
    e.ask("What's opposite to {0}?".format(to_string(s)))
    e.answer("It's {0}".format(not s))
    return not s
Beispiel #29
0
def lte(a, b, lv):
    e = Echo("lte", lv)
    e.ask("Is {0} less or equal than {1}?".format(a, b))
    e.answer("Yes.") if a <= b else e.answer("Nope")
    return a <= b
Beispiel #30
0
def sub1(n, lv):
    e = Echo("sub1", lv)
    e.ask("What is the result of subtracting 1 from {0}?".format(to_string(n)))
    e.answer("{0}.".format(n-1))
    return n-1
Beispiel #31
0
def gte(a, b, lv):
    e = Echo("gte", lv)
    e.ask("Is {0} greater or equal than {1}?".format(a, b))
    e.answer("Yes.") if a >= b else e.answer("Nope.")
    return a >= b
Beispiel #32
0
def expt(n, m, lv):
    e = Echo("expt", lv)
    e.ask("What is rasing {0} to the power of {1}".format(
        to_string(n), to_string(m)))
    e.answer("{0}.".format(n**m))
    return n**m
Beispiel #33
0
def sub(a, b, lv):
    e = Echo("sub", lv)
    e.ask("What's the result of {0} - {1}?".format(to_string(a), to_string(b)))
    e.answer("{0}.".format(a - b))
    return a - b
Beispiel #34
0
def lt(a, b, lv):
    e = Echo("lt", lv)
    e.ask("Is {0} less than {1}?".format(a, b))
    e.answer("Yes.") if a < b else e.answer("Nope.")
    return a < b
Beispiel #35
0
def add(a, b, lv):
    e = Echo("add", lv)
    e.ask("What's the result of {0} + {1}?".format(to_string(a), to_string(b)))
    e.answer("{0}.".format(a+b))
    return a+b
Beispiel #36
0
def lte(a, b, lv):
    e = Echo("lte", lv)
    e.ask("Is {0} less or equal than {1}?".format(a, b))
    e.answer("Yes.") if a <= b else e.answer("Nope")
    return a <= b
Beispiel #37
0
def add(a, b, lv):
    e = Echo("add", lv)
    e.ask("What's the result of {0} + {1}?".format(to_string(a), to_string(b)))
    e.answer("{0}.".format(a + b))
    return a + b
Beispiel #38
0
def eq(a, b, lv):
    e = Echo("eq", lv)
    e.ask("Is {0} = {1}?".format(a, b))
    e.answer("Yes.") if a == b else e.answer("Nope.")
    return a == b
Beispiel #39
0
def lt(a, b, lv):
    e = Echo("lt", lv)
    e.ask("Is {0} less than {1}?".format(a, b))
    e.answer("Yes.") if a < b else e.answer("Nope.")
    return a < b
Beispiel #40
0
def not_(s, lv):
    e = Echo("not", lv)
    e.ask("What's opposite to {0}?".format(to_string(s)))
    e.answer("It's {0}".format(not s))
    return not s
Beispiel #41
0
def mult(a, b, lv):
    e = Echo("mult", lv)
    e.ask("What's the result of {0} * {1}?".format(to_string(a) ,to_string(b)))
    e.answer("{0}.".format(a*b))
    return a*b
Beispiel #42
0
def add1(n, lv):
    e = Echo("add1", lv)
    e.ask("What is the result of adding 1 to {0}?".format(to_string(n)))
    e.answer("{0}.".format(n + 1))
    return n + 1
Beispiel #43
0
def add1(n, lv):
    e = Echo("add1", lv)
    e.ask("What is the result of adding 1 to {0}?".format(to_string(n)))
    e.answer("{0}.".format(n+1))
    return n+1
Beispiel #44
0
def gt(a, b, lv):
    e = Echo("gt", lv)
    e.ask("Is {0} greater than {1}?".format(a, b))
    e.answer("Yes.") if a > b else e.answer("Nope.")
    return a > b
Beispiel #45
0
def expt(n, m, lv):
    e = Echo("expt", lv)
    e.ask("What is rasing {0} to the power of {1}".format(to_string(n), to_string(m)))
    e.answer("{0}.".format(n**m))
    return n**m
Beispiel #46
0
def gt(a, b, lv):
    e = Echo("gt", lv)
    e.ask("Is {0} greater than {1}?".format(a, b))
    e.answer("Yes.") if a > b else e.answer("Nope.")
    return a > b
Beispiel #47
0
def gte(a, b, lv):
    e = Echo("gte", lv)
    e.ask("Is {0} greater or equal than {1}?".format(a, b))
    e.answer("Yes.") if a >= b else e.answer("Nope.")
    return a >= b
Beispiel #48
0
def eq(a, b, lv):
    e = Echo("eq", lv)
    e.ask("Is {0} = {1}?".format(a, b))
    e.answer("Yes.") if a == b else e.answer("Nope.")
    return a == b