package function.builtin;

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

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

    private ArgumentValidator argumentValidator;
    private RuntimeEnvironment environment;

    public PRINT(String name) {
        this.argumentValidator = new ArgumentValidator(name);
        this.argumentValidator.setExactNumberOfArguments(1);
        this.environment = RuntimeEnvironment.getInstance();
    }

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

        return argument;
    }

}
