package function.builtin.predicate;

import static sexpression.Nil.NIL;
import static sexpression.Symbol.T;

import function.ArgumentValidator;
import function.FunctionNames;
import function.LispFunction;
import sexpression.Cons;
import sexpression.SExpression;

@FunctionNames({ "LISTP", "LIST?" })
public class LISTP extends LispFunction {

    private ArgumentValidator argumentValidator;

    public LISTP(String name) {
        this.argumentValidator = new ArgumentValidator(name);
        this.argumentValidator.setExactNumberOfArguments(1);
    }

    @Override
    public SExpression call(Cons argumentList) {
        argumentValidator.validate(argumentList);

        return argumentList.getFirst().isList() ? T : NIL;
    }

}
