A naive implmentation of Boolean types and nil node has been added
This commit is contained in:
parent
e3b6a054b4
commit
709346311a
|
@ -5,7 +5,7 @@ public class FalseNode extends Node {
|
|||
|
||||
@Override
|
||||
public Object eval(Scope scope) {
|
||||
return false;
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -17,7 +17,7 @@ public class IfSpecialForm extends SpecialForm {
|
|||
@Override
|
||||
public Object eval(final Scope scope) {
|
||||
Object result = this.pred.eval(scope);
|
||||
if (result == null) {
|
||||
if (result == null || (result instanceof Boolean && (Boolean) result == false)) {
|
||||
return this.elseNode.eval(scope);
|
||||
}
|
||||
return this.ifNode.eval(scope);
|
||||
|
|
|
@ -43,9 +43,14 @@ public class Main {
|
|||
|
||||
if (result != ListNode.EMPTY) {
|
||||
System.out.print(";; ");
|
||||
if (result == null) {
|
||||
System.out.println("nil");
|
||||
}
|
||||
else {
|
||||
System.out.println(result.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception e) {
|
||||
System.out.println("Error: ");
|
||||
e.printStackTrace(System.out);
|
||||
|
|
|
@ -5,7 +5,7 @@ public class NilNode extends Node {
|
|||
|
||||
@Override
|
||||
public Object eval(Scope scope) {
|
||||
return this;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -83,9 +83,19 @@ public class Reader {
|
|||
str = str + (char) ch;
|
||||
}
|
||||
|
||||
switch(str) {
|
||||
case "true":
|
||||
return new TrueNode();
|
||||
case "false":
|
||||
return new FalseNode();
|
||||
case "nil":
|
||||
return new NilNode();
|
||||
default:
|
||||
return new SymbolNode(str);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static Node readNumber(PushbackReader inputStream) throws IOException {
|
||||
int ch = inputStream.read();
|
||||
String number = "";
|
||||
|
|
Loading…
Reference in New Issue