GulfOfMexico icon indicating copy to clipboard operation
GulfOfMexico copied to clipboard

Suggestion: add `undo`

Open stohrendorf opened this issue 2 years ago • 1 comments

Developers make mistakes, and a perfect language should support the developer. For example, a developer might accidentally write publishMyPrivateKeysAndPasswords()!. With undo, they can then write undo publishMyPrivateKeysAndPasswords()!, which will then generate reverse code so that the data was never published in the first place. undo undo ... undoes the undo, and vice versa. Special care must be taken when doing undo vroom (#54), because that will halt time, and undo undo vroom will create an alternative timeline. In combination with universe (#119), undo universe will create an anti-universe, and undo undo universe will create an alternative universe, etc.. undo on a variable will restore its previous value.

Update about the technical implementation:

  • Every variable is implicitly treated as a stack, and the current variable's value is the stack's top.
  • An undo assigns the value right underneath the top to it. As it is an assignment, it's effectively a x.push(x[x.length-2]).
  • An undo undo pops off the top value.
  • undo undo undo thus behaves the same as a single undo.

stohrendorf avatar Jun 10 '23 20:06 stohrendorf

This makes sense since they have to be stored as a stack anyway for next and prev to work... but what if you want to undo something that happens in the future? Maybe add a don'tdo keyword (mandatory apostrophe).

ThePython10110 avatar Jul 06 '24 01:07 ThePython10110