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

}
