static Pair map(Procedure proc, Object args, Scheme interp, Pair result)
{
Pair accum = result;
if (rest(args) == null)
{
args = first(args);
while (args is Pair)
{
Object x = proc.apply(interp, list(first(args)));
if (accum != null) accum = (Pair) (accum.rest = list(x));
args = rest(args);
}
}
else
{
Procedure car = Procedure.proc(interp.eval("car"));
Procedure cdr = Procedure.proc(interp.eval("cdr"));
while (first(args) is Pair)
{
Object x = proc.apply(interp, map(car, list(args), interp, list(null)));
if (accum != null) accum = (Pair) (accum.rest = list(x));
args = map(cdr, list(args), interp, list(null));
}
}
return (Pair)rest(result);
}