Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…bracket-fn []
  • Loading branch information...
commit aa37d65548d5658aa3608cfe40a1a388d793b575 1 parent d792435
conan dalton authored
11 src/arc/lib/tests/core-evaluation-test.arc
View
@@ -5,14 +5,15 @@
(suite "[ _ ] shortcut"
("call directly"
([* _ _] 15)
- 225
- )
+ 225)
("useful in apply"
(apply [* _ _] '(16))
- 256
- )
- )
+ 256)
+
+ ("handles empty bracket-fn"
+ ([] 21)
+ nil))
(suite "apply"
("a simple sum function"
2  src/cc/ArcParser.jj
View
@@ -194,7 +194,7 @@ ArcObject functionShortcut(): {
} {
tok = "[" (
o = expression() { list.add(o); }
- )+ "]" {
+ )* "]" {
fn.add(Pair.buildFrom(list));
return Pair.buildFrom(fn);
}
20 src/java/rainbow/functions/interpreted/InterpretedFunction.java
View
@@ -5,10 +5,7 @@
import rainbow.LexicalClosure;
import rainbow.Nil;
import rainbow.functions.Builtin;
-import rainbow.types.ArcObject;
-import rainbow.types.ArcString;
-import rainbow.types.Pair;
-import rainbow.types.Symbol;
+import rainbow.types.*;
import rainbow.vm.Instruction;
import rainbow.vm.VM;
import rainbow.vm.compiler.FunctionBodyBuilder;
@@ -16,10 +13,7 @@
import rainbow.vm.instructions.Close;
import rainbow.vm.instructions.Literal;
import rainbow.vm.instructions.PopArg;
-import rainbow.vm.interpreter.BoundSymbol;
-import rainbow.vm.interpreter.IfClause;
-import rainbow.vm.interpreter.Quotation;
-import rainbow.vm.interpreter.StackSymbol;
+import rainbow.vm.interpreter.*;
import rainbow.vm.interpreter.visitor.FunctionOwnershipVisitor;
import rainbow.vm.interpreter.visitor.MeasureLexicalReach;
import rainbow.vm.interpreter.visitor.ReferenceCounter;
@@ -332,8 +326,12 @@ public int compareTo(ArcObject right) {
public String toString() {
if (isBracketFn()) {
- String s = body[0].toString();
- return "[" + s.substring(1, s.length() - 1) + "]";
+ if (body[0] instanceof Nil) {
+ return "[]";
+ } else {
+ String s = body[0].toString();
+ return "[" + s.substring(1, s.length() - 1) + "]";
+ }
}
List<ArcObject> fn = new LinkedList<ArcObject>();
fn.add(Symbol.mkSym("fn"));
@@ -343,7 +341,7 @@ public String toString() {
}
private boolean isBracketFn() {
- return parameterList instanceof Pair && parameterList.car() == Symbol.mkSym("_") && parameterList.cdr() instanceof Nil && body.length == 1;
+ return parameterList instanceof Pair && parameterList.car() == Symbol.mkSym("_") && parameterList.cdr() instanceof Nil && body.length == 1 && !(body[0] instanceof LiteralObject);
}
public ArcObject parameterList() {
Please sign in to comment.
Something went wrong with that request. Please try again.