Undo/Redo with Clojure using the Memento Pattern
Because of the ability to attach “watch” functions to Clojure atoms, it is very easy to create and use a simple undo/redo mechanism. The approach is to create a stack that holds every change to the state of the atom, as detected by a watch function. To undo something you just pop the last state off the stack. You can repeat it until you recover the original state of the atom as it existed when you attached the watch function.