34 lines
834 B
Java
34 lines
834 B
Java
package function.builtin.special;
|
|
|
|
import static function.builtin.EVAL.eval;
|
|
|
|
import function.*;
|
|
import sexpression.*;
|
|
|
|
@FunctionNames({ "OR" })
|
|
public class OR extends LispSpecialFunction {
|
|
|
|
private ArgumentValidator argumentValidator;
|
|
|
|
public OR() {
|
|
this.argumentValidator = new ArgumentValidator("OR");
|
|
}
|
|
|
|
public SExpression call(Cons argumentList) {
|
|
argumentValidator.validate(argumentList);
|
|
|
|
return callTailRecursive(argumentList);
|
|
}
|
|
|
|
private SExpression callTailRecursive(Cons argumentList) {
|
|
SExpression currentValue = eval(argumentList.getFirst());
|
|
Cons remainingValues = (Cons) argumentList.getRest();
|
|
|
|
if (remainingValues.isNull() || !currentValue.isNull())
|
|
return currentValue;
|
|
|
|
return callTailRecursive(remainingValues);
|
|
}
|
|
|
|
}
|