The documentation for $Pre
gives the following example
SetAttributes[saveinputs, HoldAll];
inputs = {};
saveinputs[new_] := (inputs = {inputs, HoldForm[new]}; new);
$Pre = saveinputs;
Evaluating the 3 input cells a
then b
then Flatten[inputs]
gives
{a,b,Flatten[inputs]}
which is the the expected output. For some reason the intermediate step $Pre = saveinputs
is necessary, but why? If one tries to define $Pre
directly via
SetAttributes[$Pre, HoldAll];
inputs = {};
$Pre[new_] := (inputs = {inputs, HoldForm[new]}; new);
then $Pre does not work and inputs = {}
. How is this different?