package function.builtin;

import static function.builtin.APPLY.apply;
import static function.builtin.cons.LIST.makeList;

import function.*;
import sexpression.*;

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

    private ArgumentValidator argumentValidator;

    public FUNCALL() {
        this.argumentValidator = new ArgumentValidator("FUNCALL");
        this.argumentValidator.setMinimumNumberOfArguments(1);
    }

    public SExpression call(Cons argumentList) {
        argumentValidator.validate(argumentList);
        Cons applyArgs = new Cons(argumentList.getFirst(), makeList(argumentList.getRest()));

        return apply(applyArgs);
    }

}
