4
$\begingroup$

MakeBoxes has the attribute HoldAllComplete. For a normal function, it would imply that Upvalues should not be taken into account when the expression is evaluated:

In[1]:= G[F[x_]]^:=x^2 In[2]:= G[F[t]] Out[2]= t^2 In[3]:= Attributes[G]:=HoldAllComplete; G[F[t]] Out[3]= G[F[t]] 

However, if we evaluate the following code

In[1]:= MakeBoxes[Q[t_],f_]^:=SubscriptBox[t,"Q"] In[2]:= MakeBoxes[Q[t]] Out[2]= SubscriptBox[t,"Q"] 

Also, in the notebook interface, we can see that the rule is used when Q[t] is formatted: enter image description here

My question is then, why MakeBoxes does not have just the HoldAll attribute, which reproduces better how the evaluation is carried on?

$\endgroup$
3
  • 3
    $\begingroup$ MakeBoxes is meant to format anything. Compare MakeBoxes[Evaluate[Print[1]]] and SetAttributes[f, HoldAll]; f[Evaluate[Print[1]]]. $\endgroup$ Commented Nov 28, 2022 at 13:19
  • $\begingroup$ I wonder if this is related to the fact that MakeBoxes evaluation isn't like normal evaluation and inside MakeBoxes' evaluation, it ignores the HoldAllComplete attribute? $\endgroup$ Commented Nov 28, 2022 at 15:48
  • $\begingroup$ To what @GregHurst has said, I'd add that MakeBoxes seems to me the prototypical example of the reason why HoldAllComplete is needed at all, that is, why HoldAll isn't sufficient. $\endgroup$ Commented Nov 29, 2022 at 3:15

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.