sclass BStack > VStack { // alternative to backtrack to IF0 alternative; // steps to undo before switching to the alternative L undos; BStack cloneStack() { new BStack s; s.stack = shallowCloneElements(stack); ret s; } void addUndo(AutoCloseable undo) { if (undo == null) ret; if (undos == null) undos = new L; undos.add(undo); } BStack addAlternative(IVF1 action) { BStack clonedStack = cloneStack(); alternative = -> { action.get(clonedStack); ret clonedStack; }; ret clonedStack; } BStack backtrack() { if (undos != null) for (undo : reversed(getAndClearList(undos))) undo.close(); ret alternative?!; } }