I need a behaviour provided by:
x = 2;
Block[{x = HoldForm[x]}, x]
x
FrontEnd
marks this syntax as not quite correct.
It has not caused me any troubles so far so my question is: could it be a problem?
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityThe FE only looks at the structure of your code for colouring. It doesn't evaluate anything. This means two things: (1) it can only guess that there might be a problem, because by looking at the structure, it doesn't know whether your code really evaluates to something you might not want. (2) You can easily trick the FE by changing the structure into something equivalent which looks different. With this you can easily trick the FE into whatever colouring you prefer. Here are only some examples of exactly the same code:
HoldForm
wrapper inside the Block
. If you use x=HoldForm[a]
instead, everything works as expected. Look at the output of this and then replace a
by x
.
$\endgroup$
x
. I wanted to see what happens because the x
inside the HoldForm
is the global x
. Obviously they prevented it. What consequences this has for your code, I don't know.
$\endgroup$
x
will go out of scope before being used. I must admit I don't understand what this even means forHoldForm
.) $\endgroup$