Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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)
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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)
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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