plsql: add dockerfile. Lots of cleanup/renaming.
[jackhill/mal.git] / groovy / step8_macros.groovy
index 06481f6..7606526 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])
@@ -36,7 +37,8 @@ pair_Q = { ast -> types.sequential_Q(ast) && ast.size() > 0}
 quasiquote = { ast ->
     if (! pair_Q(ast)) {
         [new MalSymbol("quote"), ast]
-    } else if (ast[0].class == MalSymbol &&
+    } else if (ast[0] != null &&
+               ast[0].class == MalSymbol &&
                ast[0].value == "unquote") {
         ast[1]
     } else if (pair_Q(ast[0]) && ast[0][0].class == MalSymbol && 
@@ -68,7 +70,8 @@ EVAL = { ast, env ->
     if (! types.list_Q(ast)) return eval_ast(ast, env)
 
     ast = macroexpand(ast, env)
-    if (! types.list_Q(ast)) return ast
+    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!" }: