transcendental-lisp/src/function/builtin/special/AND.java

39 lines
946 B
Java

package function.builtin.special;
import function.*;
import function.builtin.EVAL;
import sexpression.*;
public class AND extends LispFunction {
private ArgumentValidator argumentValidator;
public AND() {
this.argumentValidator = new ArgumentValidator("AND");
}
public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList);
return callTailRecursive(argumentList, Symbol.T);
}
private SExpression callTailRecursive(Cons argumentList, SExpression lastValue) {
SExpression currentValue = EVAL.eval(argumentList.getCar());
Cons remainingValues = (Cons) argumentList.getCdr();
if (argumentList.nullp())
return lastValue;
if (currentValue.nullp())
return currentValue;
return callTailRecursive(remainingValues, currentValue);
}
public boolean evaluateArguments() {
return false;
}
}