properly implement tco and add step7:quote
[jackhill/mal.git] / groovy / step9_try.groovy
index 2d98831..2ee2626 100644 (file)
@@ -15,6 +15,7 @@ READ = { str ->
 // EVAL
 macro_Q = { ast, env ->
     if (types.list_Q(ast) &&
+        ast.size() > 0 &&
         ast[0].class == MalSymbol &&
         env.find(ast[0])) {
         def obj = env.get(ast[0])
@@ -70,6 +71,7 @@ EVAL = { ast, env ->
 
     ast = macroexpand(ast, env)
     if (! types.list_Q(ast)) return eval_ast(ast, env)
+    if (ast.size() == 0) return ast
 
     switch (ast[0]) {
     case { it instanceof MalSymbol && it.value == "def!" }:
@@ -164,9 +166,8 @@ repl_env.set(new MalSymbol("*ARGV*"), this.args as List)
 
 // core.mal: defined using mal itself
 REP("(def! not (fn* (a) (if a false true)))")
-REP("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))")
+REP("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \"\nnil)\")))))")
 REP("(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> (count xs) 1) (nth xs 1) (throw \"odd number of forms to cond\")) (cons 'cond (rest (rest xs)))))))");
-REP("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))");
 
 
 if (this.args.size() > 0) {
@@ -183,7 +184,7 @@ while (true) {
     try {
         println REP(line)
     } catch(MalException ex) {
-        println "Error: ${ex.message}"
+        println "Error: ${printer.pr_str(ex.obj, true)}"
     } catch(StackOverflowError ex) {
         println "Error: ${ex}"
     } catch(ex) {