/* * Name: Mike Cifelli * Course: CIS 443 - Programming Languages * Assignment: Lisp Interpreter 1 */ package eval; import parser.*; /** * MULTIPLY represents the '*' function in Lisp. */ public class MULTIPLY extends LispFunction { public LispNumber call(Cons argList) { if (argList.nullp()) { return new LispNumber(1); } 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() * num2.getValue()); } throw new RuntimeException("*: " + argFirst + " is not a number"); } }