Skip to content
This repository
Browse code

fix http://arclanguage.org/item?id=12542 (rocketnia) - handles empty …

…bracket-fn []
  • Loading branch information...
commit aa37d65548d5658aa3608cfe40a1a388d793b575 1 parent d792435
conan dalton authored October 12, 2010
11  src/arc/lib/tests/core-evaluation-test.arc
@@ -5,14 +5,15 @@
5 5
     (suite "[ _ ] shortcut"
6 6
       ("call directly"
7 7
         ([* _ _] 15)
8  
-        225
9  
-      )
  8
+        225)
10 9
 
11 10
       ("useful in apply"
12 11
         (apply [* _ _] '(16))
13  
-        256
14  
-      )
15  
-    )
  12
+        256)
  13
+
  14
+      ("handles empty bracket-fn"
  15
+        ([] 21)
  16
+        nil))
16 17
 
17 18
     (suite "apply"
18 19
       ("a simple sum function"
2  src/cc/ArcParser.jj
@@ -194,7 +194,7 @@ ArcObject functionShortcut(): {
194 194
                               } {
195 195
   tok = "[" (
196 196
   o = expression()            { list.add(o); }
197  
-  )+ "]"                      {
  197
+  )* "]"                      {
198 198
                                 fn.add(Pair.buildFrom(list));
199 199
                                 return Pair.buildFrom(fn);
200 200
                               }
20  src/java/rainbow/functions/interpreted/InterpretedFunction.java
@@ -5,10 +5,7 @@
5 5
 import rainbow.LexicalClosure;
6 6
 import rainbow.Nil;
7 7
 import rainbow.functions.Builtin;
8  
-import rainbow.types.ArcObject;
9  
-import rainbow.types.ArcString;
10  
-import rainbow.types.Pair;
11  
-import rainbow.types.Symbol;
  8
+import rainbow.types.*;
12 9
 import rainbow.vm.Instruction;
13 10
 import rainbow.vm.VM;
14 11
 import rainbow.vm.compiler.FunctionBodyBuilder;
@@ -16,10 +13,7 @@
16 13
 import rainbow.vm.instructions.Close;
17 14
 import rainbow.vm.instructions.Literal;
18 15
 import rainbow.vm.instructions.PopArg;
19  
-import rainbow.vm.interpreter.BoundSymbol;
20  
-import rainbow.vm.interpreter.IfClause;
21  
-import rainbow.vm.interpreter.Quotation;
22  
-import rainbow.vm.interpreter.StackSymbol;
  16
+import rainbow.vm.interpreter.*;
23 17
 import rainbow.vm.interpreter.visitor.FunctionOwnershipVisitor;
24 18
 import rainbow.vm.interpreter.visitor.MeasureLexicalReach;
25 19
 import rainbow.vm.interpreter.visitor.ReferenceCounter;
@@ -332,8 +326,12 @@ public int compareTo(ArcObject right) {
332 326
 
333 327
   public String toString() {
334 328
     if (isBracketFn()) {
335  
-      String s = body[0].toString();
336  
-      return "[" + s.substring(1, s.length() - 1) + "]";
  329
+      if (body[0] instanceof Nil) {
  330
+        return "[]";
  331
+      } else {
  332
+        String s = body[0].toString();
  333
+        return "[" + s.substring(1, s.length() - 1) + "]";
  334
+      }
337 335
     }
338 336
     List<ArcObject> fn = new LinkedList<ArcObject>();
339 337
     fn.add(Symbol.mkSym("fn"));
@@ -343,7 +341,7 @@ public String toString() {
343 341
   }
344 342
 
345 343
   private boolean isBracketFn() {
346  
-    return parameterList instanceof Pair && parameterList.car() == Symbol.mkSym("_") && parameterList.cdr() instanceof Nil && body.length == 1;
  344
+    return parameterList instanceof Pair && parameterList.car() == Symbol.mkSym("_") && parameterList.cdr() instanceof Nil && body.length == 1 && !(body[0] instanceof LiteralObject);
347 345
   }
348 346
 
349 347
   public ArcObject parameterList() {

0 notes on commit aa37d65

Please sign in to comment.
Something went wrong with that request. Please try again.