2016-12-19 13:05:53 -05:00
|
|
|
package function.builtin;
|
2016-12-07 16:38:26 -05:00
|
|
|
|
2016-12-25 13:56:24 -05:00
|
|
|
import java.math.BigInteger;
|
|
|
|
|
2016-12-19 13:05:53 -05:00
|
|
|
import function.LispFunction;
|
2016-12-15 15:33:48 -05:00
|
|
|
import sexpression.*;
|
2016-12-07 16:38:26 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* <code>MULTIPLY</code> represents the '*' function in Lisp.
|
|
|
|
*/
|
|
|
|
public class MULTIPLY extends LispFunction {
|
|
|
|
|
|
|
|
public LispNumber call(Cons argList) {
|
|
|
|
if (argList.nullp()) {
|
2016-12-25 13:56:24 -05:00
|
|
|
return new LispNumber(BigInteger.ONE);
|
2016-12-07 16:38:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
SExpression argFirst = argList.getCar();
|
|
|
|
Cons argRest = (Cons) argList.getCdr();
|
|
|
|
|
|
|
|
if (argFirst.numberp()) {
|
|
|
|
LispNumber num1 = (LispNumber) argFirst;
|
|
|
|
LispNumber num2 = call(argRest);
|
|
|
|
|
2016-12-25 13:56:24 -05:00
|
|
|
return new LispNumber(num1.getValue().multiply(num2.getValue()));
|
2016-12-07 16:38:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
throw new RuntimeException("*: " + argFirst + " is not a number");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|