package function.builtin; import function.LispFunction; import sexpression.*; /** * LIST represents the LIST function in Lisp. */ public class LIST extends LispFunction { /** * Places the given S-expression into a list. * * @param sexpr * the S-expression to be placed into a list * @return * a list with sexpr as the car and NIL as the cdr. */ public static Cons makeList(SExpression sexpr) { return new Cons(sexpr, Nil.getUniqueInstance()); } public Cons call(Cons argList) { if (argList.nullp()) { // return NIL if there were no arguments passed to LIST return Nil.getUniqueInstance(); } SExpression argCar = argList.getCar(); Cons argCdr = (Cons) argList.getCdr(); return new Cons(argCar, call(argCdr)); } }