----- Original Message ----- From: Luke Palmer <[EMAIL PROTECTED]> Date: Tuesday, June 29, 2004 7:31 pm Subject: Re: undo()? > > Oh no! Someone doesn't understand continuations! How could this > happen?! :-) > > You need two things to bring the state of the process back to an > earlierstate: 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 > overthe 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. > > > You could make the programmer specify which variables he wants delta > > data for, and then any *others* wouldn't keep it and wouldn't be > > undoable. > > > > use undo <<foo bar baz>>; # Or use the funny characters I can't > type.> my $foo++; $foo.undo(); # Undoes the increment. > > my $quux++; $quux.undo(); # Throws an exception or something. > > A much more useful way to do this would be: > > use undo << $foo $bar $baz >>; > my $foo = 41; > my $state = undo.save; > $foo++; $foo.undo($state); # or perhaps $state.remember;
Do you think it would be possible to implement C<undo> with pure Perl6 using continuations? My intuition thinks it could, but my brain starts hating me when I start to think about it... It would definitely be a pretty neat module if it could be done though. P.S. That was a truly spectacular explanation of continuations. :)