package function.builtin.cons;

import function.*;
import sexpression.*;

@FunctionNames({ "CONS" })
public class CONS extends LispFunction {

    private ArgumentValidator argumentValidator;

    public CONS() {
        this.argumentValidator = new ArgumentValidator("CONS");
        this.argumentValidator.setExactNumberOfArguments(2);
    }

    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);
    }

}
