43 lines
1.0 KiB
Java
43 lines
1.0 KiB
Java
package function.builtin;
|
|
|
|
import java.math.BigInteger;
|
|
|
|
import function.ArgumentValidator;
|
|
import function.FunctionNames;
|
|
import function.LispFunction;
|
|
import sexpression.Cons;
|
|
import sexpression.SExpression;
|
|
import sexpression.Symbol;
|
|
|
|
@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);
|
|
}
|
|
|
|
@Override
|
|
public SExpression call(Cons argumentList) {
|
|
argumentValidator.validate(argumentList);
|
|
|
|
return generateSymbol();
|
|
}
|
|
}
|