package function.builtin; import function.*; import sexpression.*; public class APPLY extends LispFunction { private ArgumentValidator argumentValidator; public static SExpression apply(Cons argList) { return new APPLY().call(argList); } public APPLY() { this.argumentValidator = new ArgumentValidator("APPLY"); this.argumentValidator.setExactNumberOfArguments(2); this.argumentValidator.setTrailingArgumentExpectedType(Cons.class); } public SExpression call(Cons argList) { argumentValidator.validate(argList); Cons cdr = (Cons) argList.getCdr(); SExpression functionName = argList.getCar(); SExpression argumentList = cdr.getCar(); LispFunction function = EVAL.lookupFunctionOrLambda(functionName); return function.call((Cons) argumentList); } }