transcendental-lisp/eval/ATOM.java

39 lines
1.0 KiB
Java

/*
* Name: Mike Cifelli
* Course: CIS 443 - Programming Languages
* Assignment: Lisp Interpreter 1
*/
package eval;
import parser.*;
/**
* <code>ATOM</code> represents the ATOM function in Lisp.
*/
public class ATOM extends LispFunction {
// The number of arguments that ATOM takes.
private static final int NUM_ARGS = 1;
public SExpression call(Cons argList) {
// retrieve the number of arguments passed to ATOM
int argListLength = LENGTH.getLength(argList);
// make sure we have received the proper number of arguments
if (argListLength != NUM_ARGS) {
Cons originalSExpr = new Cons(new Symbol("ATOM"), argList);
String errMsg = "too " +
((argListLength > NUM_ARGS) ? "many" : "few") +
" arguments given to ATOM: " + originalSExpr;
throw new RuntimeException(errMsg);
}
SExpression arg = argList.getCar();
return (arg.atomp() ? Symbol.T : Nil.getUniqueInstance());
}
}