30 lines
804 B
Java
30 lines
804 B
Java
package function.builtin.cons;
|
|
|
|
import function.ArgumentValidator;
|
|
import function.FunctionNames;
|
|
import function.LispFunction;
|
|
import sexpression.Cons;
|
|
import sexpression.SExpression;
|
|
|
|
@FunctionNames({ "CONS" })
|
|
public class CONS extends LispFunction {
|
|
|
|
private ArgumentValidator argumentValidator;
|
|
|
|
public CONS(String name) {
|
|
this.argumentValidator = new ArgumentValidator(name);
|
|
this.argumentValidator.setExactNumberOfArguments(2);
|
|
}
|
|
|
|
@Override
|
|
public Cons call(Cons argumentList) {
|
|
argumentValidator.validate(argumentList);
|
|
|
|
Cons rest = (Cons) argumentList.getRest();
|
|
SExpression firstArgument = argumentList.getFirst();
|
|
SExpression secondArgument = rest.getFirst();
|
|
|
|
return new Cons(firstArgument, secondArgument);
|
|
}
|
|
}
|