transcendental-lisp/src/function/builtin/special/SETF.java

34 lines
932 B
Java

package function.builtin.special;
import static function.builtin.EVAL.eval;
import static function.builtin.SET.set;
import static function.builtin.cons.LIST.makeList;
import function.*;
import sexpression.*;
public class SETF extends LispSpecialFunction {
private ArgumentValidator argumentValidator;
public SETF() {
this.argumentValidator = new ArgumentValidator("SETF");
this.argumentValidator.setExactNumberOfArguments(2);
this.argumentValidator.setFirstArgumentExpectedType(Symbol.class);
}
public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList);
return set(evaluateValueOnly(argumentList));
}
private Cons evaluateValueOnly(Cons argumentList) {
Cons rest = (Cons) argumentList.getRest();
SExpression value = eval(rest.getFirst());
return new Cons(argumentList.getFirst(), makeList(value));
}
}