Skip to content

Commit

Permalink
Make it possible to assign a place that doesn't exist, and then have …
Browse files Browse the repository at this point in the history
…it disappear again. This allows temporary overriding in the manner of categories, for specific cells
  • Loading branch information
olabini committed Jan 10, 2009
1 parent e294578 commit 8af3954
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/main/ioke/lang/FlowControlBehavior.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ public Object activate(IokeObject method, IokeObject context, IokeObject message
wherePlace = Message.getEvaluatedArgument(place, context);
}

Object originalValue = realPlace.sendTo(context, wherePlace);
Object originalValue = null;
try {
originalValue = realPlace.sendTo(context, wherePlace);
} catch(Throwable e) {
originalValue = null;
}

if(realPlace.getArguments().size() != 0) {
String newName = realPlace.getName() + "=";
Expand Down Expand Up @@ -96,10 +101,24 @@ public Object activate(IokeObject method, IokeObject context, IokeObject message
if(realPlace.getArguments().size() != 0) {
String newName = realPlace.getName() + "=";
List<Object> arguments = new ArrayList<Object>(realPlace.getArguments());
arguments.add(context.runtime.createMessage(Message.wrap(IokeObject.as(value))));
context.runtime.newMessageFrom(realPlace, newName, arguments).sendTo(context, wherePlace);

if(value == null) {
if(newName.equals("cell=")) {
context.runtime.removeCellMessage.sendTo(context, wherePlace, new ArrayList<Object>(realPlace.getArguments()));
} else {
arguments.add(context.runtime.createMessage(Message.wrap(context.runtime.nil)));
context.runtime.newMessageFrom(realPlace, newName, arguments).sendTo(context, wherePlace);
}
} else {
arguments.add(context.runtime.createMessage(Message.wrap(IokeObject.as(value))));
context.runtime.newMessageFrom(realPlace, newName, arguments).sendTo(context, wherePlace);
}
} else {
IokeObject.assign(wherePlace, realPlace.getName(), value, context, message);
if(value == null) {
IokeObject.removeCell(wherePlace, context, message, realPlace.getName());
} else {
IokeObject.assign(wherePlace, realPlace.getName(), value, context, message);
}
}
} catch(Throwable e) {}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/ioke/lang/Runtime.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ public class Runtime {
public IokeObject inspectMessage = newMessage("inspect");
public IokeObject noticeMessage = newMessage("notice");

public IokeObject removeCellMessage = newMessage("removeCell!");

public IokeObject plusMessage = newMessage("+");
public IokeObject minusMessage = newMessage("-");
public IokeObject multMessage = newMessage("*");
Expand Down
16 changes: 16 additions & 0 deletions test/let_spec.ik
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ describe(DefaultBehavior,
error!("non-local yay!")))
Text fluxie2 wowsie should == 13
)

it("should bind a new place temporarily, and then remove it",
X = Origin mimic
let(X testOfLetMethod, method(42),
X testOfLetMethod should == 42
)
X cellNames should not include(:testOfLetMethod)
)

it("should bind a new place with cell temporarily, and then remove it",
X = Origin mimic
let(X cell(:testOfLetMethod2), method(42),
X testOfLetMethod2 should == 42
)
X cellNames should not include(:testOfLetMethod2)
)
)
)
)
Expand Down

0 comments on commit 8af3954

Please sign in to comment.