package function.builtin; import java.math.BigInteger; import function.LispFunction; import sexpression.*; /** * MULTIPLY represents the '*' function in Lisp. */ public class MULTIPLY extends LispFunction { public LispNumber call(Cons argList) { if (argList.nullp()) { return new LispNumber(BigInteger.ONE); } SExpression argFirst = argList.getCar(); Cons argRest = (Cons) argList.getCdr(); if (argFirst.numberp()) { LispNumber num1 = (LispNumber) argFirst; LispNumber num2 = call(argRest); return new LispNumber(num1.getValue().multiply(num2.getValue())); } throw new RuntimeException("*: " + argFirst + " is not a number"); } }