remove debug function
[jackhill/mal.git] / process / step2_eval.txt
CommitLineData
f5223195
JM
1--- step2_eval ----------------------------------
2import types, reader, printer
3
4READ(str): return reader.read_str(str)
5
6eval_ast(ast,env):
7 switch type(ast):
8 symbol: return lookup(env, ast) OR raise "'" + ast + "' not found"
9 list,vector: return ast.map((x) -> EVAL(x,env))
10 hash: return ast.map((k,v) -> list(k, EVAL(v,env)))
11 _default_: return ast
12
13EVAL(ast,env):
14 if not list?(ast): return eval_ast(ast, env)
1af7aff1 15 if empty?(ast): return ast
f5223195
JM
16 f, args = eval_ast(ast, env)
17 return apply(f, args)
18
19PRINT(exp): return printer.pr_str(exp)
20
21repl_env = {'+: add_fn, ...}
22rep(str): return PRINT(EVAL(READ(str),repl_env))
23
24main loop:
25 try: println(rep(readline("user> ")))
26 catch e: println("Error: ", e)