cons、quote、+ を実装したところ。
もすこしうまくいったらそのうちのせます。

consはこんな感じ。

public class ConsFunction implements IFunction{
    @Override
    public Sexp eval(Cell cell, Map<String, Sexp> env) throws FunctionException{
        if(cell.getCdr().length > 2){
            throw new FunctionException("cons: expects 2 arguments");
        }

1
2
3
4
5
6
7
8
9
    Sexp[] cdr;
    <span class="synStatement">if</span>(cell.getCdr()[<span class="synConstant">1</span>] <span class="synStatement">instanceof</span> Cell){
        cdr = ((Cell)cell.getCdr()[<span class="synConstant">1</span>]).getSexps();
    }<span class="synStatement">else</span>{
        cdr = <span class="synStatement">new</span> Sexp[]{cell.getCdr()[<span class="synConstant">1</span>]};
    }

    <span class="synStatement">return</span> <span class="synStatement">new</span> Cell(cell.getCdr()[<span class="synConstant">0</span>], cdr);
}

}