Example #1
0
def s(name):
    "Return a MalSymbol named s."
    return reader.MalSymbol(name)
Example #2
0
import sys
import readline
import reader
import printer


class EvalException(Exception):
    """Won't cause the repl to crash, but aborts reading current form"""
    pass


REPL_ENV = {
    reader.MalSymbol('+'): lambda a, b: a + b,
    reader.MalSymbol('-'): lambda a, b: a - b,
    reader.MalSymbol('*'): lambda a, b: a * b,
    reader.MalSymbol('/'): lambda a, b: int(a / b)
}


def eval_ast(form, env):
    if isinstance(form, reader.MalSymbol):
        result = env.get(form)
        if result is None:
            raise EvalException('could not find symbol: ' + form.name)
        return result
    elif isinstance(form, reader.MalList):
        return [EVAL(x, env) for x in form.value]
    elif isinstance(form, list):
        return [EVAL(x, env) for x in form]
    elif isinstance(form, dict):
        result = {}