transcendental-lisp/src/function/builtin/LIST.java

36 lines
876 B
Java
Raw Normal View History

2016-12-19 13:05:53 -05:00
package function.builtin;
2016-12-07 16:38:26 -05:00
2016-12-19 13:05:53 -05:00
import function.LispFunction;
import sexpression.*;
2016-12-07 16:38:26 -05:00
/**
* <code>LIST</code> 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 <code>sexpr</code> 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));
}
}