transcendental-lisp/src/main/kotlin/function/builtin/cons/REST.java
2018-03-23 18:12:47 -04:00

28 lines
759 B
Java

package function.builtin.cons;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispFunction;
import sexpression.Cons;
import sexpression.SExpression;
@FunctionNames({ "REST", "CDR" })
public class REST extends LispFunction {
private ArgumentValidator argumentValidator;
public REST(String name) {
this.argumentValidator = new ArgumentValidator(name);
this.argumentValidator.setExactNumberOfArguments(1);
this.argumentValidator.setEveryArgumentExpectedType(Cons.class);
}
@Override
public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList);
Cons argument = (Cons) argumentList.getFirst();
return argument.getRest();
}
}