๐Ÿ‘จ๐Ÿปโ€๐ŸŽ“ Computer Science

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.

โ€” Luke Palmer
source @ Perl user group