import sys, traceback
import mal_readline
import mal_types as types
-from mal_types import (MalSym, MalInt, MalStr, nil, true, false,
- _symbol, _keywordu, MalList, _list, MalFunc)
+from mal_types import (MalSym, MalInt, MalStr,
+ nil, true, false, _symbol, _keywordu,
+ MalList, _list, MalVector, MalHashMap, MalFunc)
import reader, printer
from env import Env
import core
for a in ast.values:
res.append(EVAL(a, env))
return MalList(res)
-## elif types._vector_Q(ast):
-## return types._vector(*map(lambda a: EVAL(a, env), ast))
-## elif types._hash_map_Q(ast):
-## keyvals = []
-## for k in ast.keys():
-## keyvals.append(EVAL(k, env))
-## keyvals.append(EVAL(ast[k], env))
-## return types._hash_map(*keyvals)
+ elif types._vector_Q(ast):
+ res = []
+ for a in ast.values:
+ res.append(EVAL(a, env))
+ return MalVector(res)
+ elif types._hash_map_Q(ast):
+ new_dct = {}
+ for k in ast.dct.keys():
+ new_dct[k] = EVAL(ast.dct[k], env)
+ return MalHashMap(new_dct)
else:
return ast # primitive value, return unchanged
#print("EVAL %s" % printer._pr_str(ast))
if not types._list_Q(ast):
return eval_ast(ast, env)
+ if len(ast) == 0: return ast
# apply list
ast = macroexpand(ast, env)
- if not types._list_Q(ast): return ast
+ if not types._list_Q(ast):
+ return eval_ast(ast, env)
if len(ast) == 0: return ast
a0 = ast[0]
if isinstance(a0, MalSym):
break
except reader.Blank:
continue
+ except types.MalException as e:
+ print(u"Error: %s" % printer._pr_str(e.object, False))
except Exception as e:
- print("%s" % e)
+ print("Error: %s" % e)
#print("".join(traceback.format_exception(*sys.exc_info())))
return 0