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(); } }