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 argumentList) { argumentValidator.validate(argumentList); Cons cdr = (Cons) argumentList.getCdr(); SExpression functionName = argumentList.getCar(); SExpression functionArguments = cdr.getCar(); LispFunction function = EVAL.lookupFunctionOrLambda(functionName); return function.call((Cons) functionArguments); } }