/* * Name: Mike Cifelli * Course: CIS 443 - Programming Languages * Assignment: Lisp Interpreter 1 */ package eval; import parser.*; /** * LISTP represents the LISTP function in Lisp. */ public class LISTP extends LispFunction { // The number of arguments that LISTP takes. private static final int NUM_ARGS = 1; public SExpression call(Cons argList) { // retrieve the number of arguments passed to LISTP 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("LISTP"), argList); String errMsg = "too " + ((argListLength > NUM_ARGS) ? "many" : "few") + " arguments given to LISTP: " + originalSExpr; throw new RuntimeException(errMsg); } SExpression arg = argList.getCar(); return (arg.listp() ? Symbol.T : Nil.getUniqueInstance()); } }