wolfram mathematica - How to intercept assigning new value for the In variable? -


i wish intercept assigning new values in variable.

i have tried defining upvalues in not in 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 possible intercept it?

p.s. question has arisen part of previous question on stage when mathematica creates new symbols.

edit

i wish intercept explicitly assignment new downvalue in variable. $pre executes after assignment , after creating new symbols in current $context:

in[1]:= $pre := (print[names["`*"]];     print[downvalues[in][[all, 1]]]; ##) &  in[2]:=  during evaluation of in[2]:= {a}  during evaluation of in[2]:= {holdpattern[in[1]],holdpattern[in[2]]}  out[2]= 

have looked @ $pre , $preread?

$pre global variable value, if set, applied every input expression.

$preread global variable value, if set, applied text or box form of every input expression before fed mathematica.

update (now better example)

in[1]:= $pre =    function[{x}, print["in[",$line,"] is: ", unevaluated[x]]; x, holdfirst];  in[2]:= 2 + 2  during evaluation of in[2]:= in[2] is: 2+2  out[2]= 4  in[3]:= instring[2]  during evaluation of in[3]:= in[3] is: instring[2]  out[3]= "\\(2 + 2\\)" 

update 2

replace $pre $preread in code above , close want, believe:

in[1]:= $preread = function[{x}, print[names["`*"]]; x, holdfirst]  out[1]= function[{x}, print[names["`*"]]; x, holdfirst]  in[2]:= = 1  during evaluation of in[2]:= {x}  out[2]= 1  in[3]:= b = 2  during evaluation of in[3]:= {a,x}  out[3]= 2 

it's not possible intercept in @ *value level because kernel not interacting in via value manipulation in "top-level" mathematica code.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -