transcendental-lisp/src/function/builtin/APPLY.java

32 lines
865 B
Java
Raw Normal View History

2016-12-19 13:05:53 -05:00
package function.builtin;
2016-12-07 16:38:26 -05:00
2016-12-19 13:05:53 -05:00
import function.*;
import sexpression.*;
2016-12-07 16:38:26 -05:00
public class APPLY extends LispFunction {
private ArgumentValidator argumentValidator;
2016-12-07 16:38:26 -05:00
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);
}
2016-12-07 16:38:26 -05:00
public SExpression call(Cons argList) {
argumentValidator.validate(argList);
2016-12-07 16:38:26 -05:00
Cons cdr = (Cons) argList.getCdr();
SExpression functionName = argList.getCar();
SExpression argumentList = cdr.getCar();
LispFunction function = EVAL.lookupFunctionOrLambda(functionName);
2016-12-07 16:38:26 -05:00
return function.call((Cons) argumentList);
2016-12-07 16:38:26 -05:00
}
}