}
public void apply(final RippleList arg,
final Sink<RippleList> solutions,
final ModelConnection mc) throws RippleException {
RippleList stack = arg;
final int index = mc.toNumericValue(stack.getFirst()).intValue();
stack = stack.getRest();
RippleValue l = stack.getFirst();
final RippleList rest = stack.getRest();
Sink<RippleList> listSink = new Sink<RippleList>() {
public void put(RippleList list) throws RippleException {
if (list.isNil()) {
throw new RippleException("list index out of bounds: " + index);
}
if (index < 1) {
throw new RippleException("list index out of bounds (note: 'at' begins counting at 1): " + index);
}
for (int j = 1; j < index; j++) {
list = list.getRest();
if (list.isNil()) {
throw new RippleException("list index out of bounds: " + index);
}
}
solutions.put(
rest.push(list.getFirst()));
}
};
mc.toList(l, listSink);
}