new L undoList; void addUndo(UndoableWithAnswer undo) { if (undo == null) ret; undoList.add(undo); change(); print("Undo added: " + undo); } void clearUndos q { if (empty(undoList)) ret; undoList.clear(); change; print("Undo list cleared"); } S singleUndo() { UndoableWithAnswer undo = popLast(undoList); if (undo == null) ret "Nothing to undo"; change(); ret or2(undo.undo(), "Last action undone"); } S undoActions(S s) { if "undo" ret singleUndo(); if "anything to undo" ret empty(undoList) ? "Nothing to undo" : n2(undoList, "undoable action"); if "clear undos" ret "OK" with clearUndos(); null; } // API UndoableWithAnswer lastUndo() { ret dm_q(() -> last(undoList)); }