26 lines
601 B
Java
26 lines
601 B
Java
package serene.simple;
|
|
|
|
|
|
public class IfSpecialForm extends SpecialForm {
|
|
|
|
private Node pred;
|
|
private Node ifNode;
|
|
private Node elseNode;
|
|
|
|
public IfSpecialForm(ListNode<Node> l) {
|
|
super(l);
|
|
this.pred = l.rest().first();
|
|
this.ifNode = l.rest().rest().first();
|
|
this.elseNode = l.rest().rest().rest().first();
|
|
}
|
|
|
|
@Override
|
|
public Object eval(final Scope scope) {
|
|
Object result = this.pred.eval(scope);
|
|
if (result == null) {
|
|
return this.elseNode.eval(scope);
|
|
}
|
|
return this.ifNode.eval(scope);
|
|
}
|
|
}
|