2017-01-14 18:01:14 -05:00
|
|
|
package function.builtin.cons;
|
2016-12-07 16:38:26 -05:00
|
|
|
|
2017-01-06 17:10:00 -05:00
|
|
|
import function.*;
|
2016-12-15 15:33:48 -05:00
|
|
|
import sexpression.*;
|
2016-12-07 16:38:26 -05:00
|
|
|
|
|
|
|
public class LIST extends LispFunction {
|
|
|
|
|
2017-01-06 17:10:00 -05:00
|
|
|
private ArgumentValidator argumentValidator;
|
|
|
|
|
|
|
|
public LIST() {
|
|
|
|
this.argumentValidator = new ArgumentValidator("LIST");
|
|
|
|
}
|
|
|
|
|
2016-12-07 16:38:26 -05:00
|
|
|
public static Cons makeList(SExpression sexpr) {
|
2016-12-29 13:32:45 -05:00
|
|
|
return new Cons(sexpr, Nil.getInstance());
|
2016-12-07 16:38:26 -05:00
|
|
|
}
|
|
|
|
|
2017-01-06 17:10:00 -05:00
|
|
|
public Cons call(Cons argumentList) {
|
|
|
|
argumentValidator.validate(argumentList);
|
|
|
|
|
|
|
|
return callRecursive(argumentList);
|
|
|
|
}
|
|
|
|
|
|
|
|
private Cons callRecursive(Cons argumentList) {
|
2017-02-25 17:29:37 -05:00
|
|
|
if (argumentList.isNull())
|
2016-12-29 13:32:45 -05:00
|
|
|
return Nil.getInstance();
|
2016-12-07 16:38:26 -05:00
|
|
|
|
2017-02-24 11:07:06 -05:00
|
|
|
SExpression firstArgument = argumentList.getFirst();
|
|
|
|
Cons remainingArguments = (Cons) argumentList.getRest();
|
2016-12-07 16:38:26 -05:00
|
|
|
|
2017-01-06 17:10:00 -05:00
|
|
|
return new Cons(firstArgument, callRecursive(remainingArguments));
|
2016-12-07 16:38:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|