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

32 lines
895 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 argumentList) {
argumentValidator.validate(argumentList);
2016-12-07 16:38:26 -05:00
Cons cdr = (Cons) argumentList.getCdr();
SExpression functionName = argumentList.getCar();
SExpression functionArguments = cdr.getCar();
LispFunction function = EVAL.lookupFunctionOrLambda(functionName);
2016-12-07 16:38:26 -05:00
return function.call((Cons) functionArguments);
2016-12-07 16:38:26 -05:00
}
}