diff options
| author | Joel Martin <github@martintribe.org> | 2015-01-08 22:56:12 -0600 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2015-01-08 22:56:12 -0600 |
| commit | fd888612ca589d7e1a46c36fc3fe12aed126f6a8 (patch) | |
| tree | 5c2bc8acc58f67bbd2b638ee744f429a38a51fbc /template/step2_eval.txt | |
| parent | 5e02d6956c49f24393676ad21a851351d9b58575 (diff) | |
| download | mal-fd888612ca589d7e1a46c36fc3fe12aed126f6a8.tar.gz mal-fd888612ca589d7e1a46c36fc3fe12aed126f6a8.zip | |
Move template to top level. Add license.
Also, cleanup TODO a bit.
Diffstat (limited to 'template/step2_eval.txt')
| -rw-r--r-- | template/step2_eval.txt | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/template/step2_eval.txt b/template/step2_eval.txt new file mode 100644 index 0000000..beb5500 --- /dev/null +++ b/template/step2_eval.txt @@ -0,0 +1,25 @@ +--- step2_eval ---------------------------------- +import types, reader, printer + +READ(str): return reader.read_str(str) + +eval_ast(ast,env): + switch type(ast): + symbol: return lookup(env, ast) OR raise "'" + ast + "' not found" + list,vector: return ast.map((x) -> EVAL(x,env)) + hash: return ast.map((k,v) -> list(k, EVAL(v,env))) + _default_: return ast + +EVAL(ast,env): + if not list?(ast): return eval_ast(ast, env) + f, args = eval_ast(ast, env) + return apply(f, args) + +PRINT(exp): return printer.pr_str(exp) + +repl_env = {'+: add_fn, ...} +rep(str): return PRINT(EVAL(READ(str),repl_env)) + +main loop: + try: println(rep(readline("user> "))) + catch e: println("Error: ", e) |
