28 lines
817 B
Java
28 lines
817 B
Java
package function.builtin.math;
|
|
|
|
import function.*;
|
|
import sexpression.*;
|
|
|
|
public class MULTIPLY extends LispFunction {
|
|
|
|
private ArgumentValidator argumentValidator;
|
|
private MathFunction mathFunction;
|
|
|
|
public MULTIPLY() {
|
|
this.argumentValidator = new ArgumentValidator("*");
|
|
this.argumentValidator.setEveryArgumentExpectedType(LispNumber.class);
|
|
this.mathFunction = new MathFunction(number -> number, this::multiply);
|
|
}
|
|
|
|
public SExpression call(Cons argumentList) {
|
|
argumentValidator.validate(argumentList);
|
|
|
|
return mathFunction.callTailRecursive(new Cons(LispNumber.ONE, argumentList));
|
|
}
|
|
|
|
private LispNumber multiply(LispNumber number1, LispNumber number2) {
|
|
return new LispNumber(number1.getValue().multiply(number2.getValue()));
|
|
}
|
|
|
|
}
|