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({ "ATOM", "ATOM?" })
public class ATOM extends LispFunction {

    private ArgumentValidator argumentValidator;

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

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

        return argument.isAtom() ? T : NIL;
    }

}
