transcendental-lisp/src/function/builtin/GENSYM.java
2017-03-10 13:19:09 -05:00

39 lines
873 B
Java

package function.builtin;
import java.math.BigInteger;
import function.*;
import sexpression.*;
@FunctionNames({ "GENSYM" })
public class GENSYM extends LispFunction {
public static final String GENSYM_PREFIX = "#G";
private static BigInteger counter = BigInteger.ZERO;
private static Symbol generateSymbol() {
incrementCounter();
return new Symbol(GENSYM_PREFIX + counter);
}
private static void incrementCounter() {
counter = counter.add(BigInteger.ONE);
}
private ArgumentValidator argumentValidator;
public GENSYM(String name) {
this.argumentValidator = new ArgumentValidator(name);
this.argumentValidator.setMaximumNumberOfArguments(0);
}
public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList);
return generateSymbol();
}
}