crystal,java: fix empty list handling.
authorJoel Martin <github@martintribe.org>
Tue, 7 May 2019 22:44:16 +0000 (17:44 -0500)
committerJoel Martin <github@martintribe.org>
Tue, 7 May 2019 22:44:48 +0000 (17:44 -0500)
crystal/step8_macros.cr
crystal/step9_try.cr
crystal/stepA_mal.cr
java/src/main/java/mal/step8_macros.java
java/src/main/java/mal/step9_try.java
java/src/main/java/mal/stepA_mal.java

index f7b5cb3..cca3710 100755 (executable)
@@ -87,6 +87,7 @@ module Mal
   def macro_call?(ast, env)
     list = ast.unwrap
     return false unless list.is_a? Mal::List
+    return false if list.empty?
 
     sym = list.first.unwrap
     return false unless sym.is_a? Mal::Symbol
@@ -136,7 +137,10 @@ module Mal
     # 'next' in 'do...end' has a bug in crystal 0.7.1
     # https://github.com/manastech/crystal/issues/659
     while true
-      return eval_ast(ast, env) unless ast.unwrap.is_a? Mal::List
+      list = ast.unwrap
+
+      return eval_ast(ast, env) unless list.is_a? Mal::List
+      return ast if list.empty?
 
       ast = macroexpand(ast, env)
 
index 0de286f..5d63bc8 100755 (executable)
@@ -87,6 +87,7 @@ module Mal
   def macro_call?(ast, env)
     list = ast.unwrap
     return false unless list.is_a? Mal::List
+    return false if list.empty?
 
     sym = list.first.unwrap
     return false unless sym.is_a? Mal::Symbol
@@ -136,7 +137,10 @@ module Mal
     # 'next' in 'do...end' has a bug in crystal 0.7.1
     # https://github.com/manastech/crystal/issues/659
     while true
-      return eval_ast(ast, env) unless ast.unwrap.is_a? Mal::List
+      list = ast.unwrap
+
+      return eval_ast(ast, env) unless list.is_a? Mal::List
+      return ast if list.empty?
 
       ast = macroexpand(ast, env)
 
index bf1a201..e8af4fb 100755 (executable)
@@ -143,7 +143,10 @@ module Mal
     # 'next' in 'do...end' has a bug in crystal 0.7.1
     # https://github.com/manastech/crystal/issues/659
     while true
-      return eval_ast(ast, env) unless ast.unwrap.is_a? Mal::List
+      list = ast.unwrap
+
+      return eval_ast(ast, env) unless list.is_a? Mal::List
+      return ast if list.empty?
 
       ast = macroexpand(ast, env)
 
index a109a88..c2fec4f 100644 (file)
@@ -107,6 +107,7 @@ public class step8_macros {
         if (!orig_ast.list_Q()) {
             return eval_ast(orig_ast, env);
         }
+        if (((MalList)orig_ast).size() == 0) { return orig_ast; }
 
         // apply list
         MalVal expanded = macroexpand(orig_ast, env);
index e5f77f5..1262bd8 100644 (file)
@@ -109,6 +109,7 @@ public class step9_try {
         if (!orig_ast.list_Q()) {
             return eval_ast(orig_ast, env);
         }
+        if (((MalList)orig_ast).size() == 0) { return orig_ast; }
 
         // apply list
         MalVal expanded = macroexpand(orig_ast, env);
index c4162c6..6bd36bc 100644 (file)
@@ -109,6 +109,7 @@ public class stepA_mal {
         if (!orig_ast.list_Q()) {
             return eval_ast(orig_ast, env);
         }
+        if (((MalList)orig_ast).size() == 0) { return orig_ast; }
 
         // apply list
         MalVal expanded = macroexpand(orig_ast, env);