Continuation
You need two things to bring the state of the process back to an earlier state: undo and continuations. People say continuations are like time traveling; I like to put it this way:
Say youโre in the kitchen in front of the refrigerator, thinking about a sandwitch. You take a continuation right there and stick it in your pocket. Then you get some turkey and bread out of the refrigerator and make yourself a sandwitch, which is now sitting on the counter. You invoke the continuation in your pocket, and you find yourself standing in front of the refrigerator again, thinking about a sandwitch. But fortunately, thereโs a sandwitch on the counter, and all the materials used to make it are gone. So you eat it. :-)
A continuation doesnโt save data. Itโs just a closure that closes over the execution stack (and any lexicals associated with it; thus the "I want a sandwitch" thought). If things change between the taking and invoking of the continuation, those things remain changed after invoking.
source @ Perl user group