I wish to intercept assigning new values for the In variable.
I have tried to do this by defining UpValues for In but it does not help in this case:
Unprotect[In];
In /: Set[In[line_], expr_] /; ! TrueQ[$InsideSet] :=
Block[{$InsideSet = True},
Print[HoldForm@HoldForm[expr]; Set[In[line], expr]]]
In /: SetDelayed[In[line_], expr_] /; ! TrueQ[$InsideSet] :=
Block[{$InsideSet = True},
Print[HoldForm@HoldForm[expr]; SetDelayed[In[line], expr]]]
Is it possible to intercept it?
P.S. This question has arisen as a part of previous question on the stage when Mathematica creates new Symbols.
EDIT
I would wish to intercept explicitly the assignment new DownValue for the In variable. $Pre executes after this assignment and after creating all new Symbols in the current $Context:
In[1]:= $Pre := (Print[Names["`*"]];
Print[DownValues[In][[All, 1]]]; ##) &
In[2]:= a
During evaluation of In[2]:= {a}
During evaluation of In[2]:= {HoldPattern[In[1]],HoldPattern[In[2]]}
Out[2]= a
Have you looked at
$Preand$PreRead?$Preis a global variable whose value, if set, is applied to every input expression.$PreReadis a global variable whose value, if set, is applied to the text or box form of every input expression before it is fed to Mathematica.UPDATE (now with better example)
UPDATE 2
Replace
$Prewith$PreReadin my code above and you get close to what you want, I believe:It’s not possible to intercept
Inat the*Valuelevel because the Kernel is simply not interacting withInvia value manipulation in “top-level” Mathematica code.