How to release $Mathematica$ from the $Pre HoldAllComplete lock Not sure if posted before, but I'm asking this question from a Mathematica fellow user who tried to load expressions, whose problem soon turned into a prison break game featuring the following code. SetAttributes[hold, HoldAllComplete]; GetOut /: hold[GetOut] := Unset[$Pre];

$Pre = hold;  After executing this code, all subsequent evaluations are hold, including the GetOut "key" and the reset expression. GetOut$Pre = .


Are there any ways to unhold subsequent evaluations, in addition to rebooting Mathematica?

-
Are you looking for a good solution, or the user's physical integrity should be preserved? –  belisarius Oct 26 '13 at 2:36
@belisarius Definitely both, if possible. I don't feel like hurting executed evaluations preceeding the lock. –  FrenzY DT. Oct 26 '13 at 2:39
Good question. I've always just restarted my kernel when I bungle up $Pre or $PreRead, since I didn't think there was any other way around. Would be interesting if there was... –  rm -rf Oct 26 '13 at 2:46
@rm-rf It's interesting that once we change HoldAllComplete to Hold, both the original attempts work. –  FrenzY DT. Oct 26 '13 at 2:49
Ooh... I have a way out. Writing an answer. –  rm -rf Oct 26 '13 at 2:52

There's nothing that can break out of a HoldAllComplete as long as it has to pass through the kernel. But what if we had a way to bypass the kernel? Hmmm... buttons!

I suggest using the following button as an escape mechanism instead of your GetOut:

Button["Clear $Pre", Unset[$Pre]]


With this, you can clear $Pre by simply clicking it — even with the HoldAllComplete. It works because the evaluation is done via the Front End and not the kernel, thus bypassing $Pre.

-
How does the Button function get evaluated? Is it through the Front End? –  FrenzY DT. Oct 26 '13 at 4:34
@FrenzYDT. Read the last paragraph? –  Sjoerd C. de Vries Oct 26 '13 at 6:45