What is the reason for built-in symbols to be Protected?

What happens if I Unprotect built-ins and add my own SetDelayed, etc.? Is it degraded performance?

What are general precautions in doing that?

My particular scenario is that I want to add custom formatting to Hold[] expressions and I can not assign because tag Hold is protected. Will this affect performance if I unprotect and do it anyways?

  • $\begingroup$ You can also assign values to Format if you are just interested in appearance. $\endgroup$
    – LLlAMnYP
    Commented Jul 3, 2017 at 16:25
  • 4
    $\begingroup$ No, it is not safe to Unprotect everything. The implication is more bugs in your code and wasting your time finding them. $\endgroup$
    – Nasser
    Commented Jul 3, 2017 at 16:47
  • 3
    $\begingroup$ You should edit this question to focus it on real problem: changing the appearance of held expressions. $\endgroup$
    – m_goldberg
    Commented Jul 3, 2017 at 19:04
  • $\begingroup$ I'm really sorry, I understand this is unproductive but unprotecting all built-ins AND modifying Hold? lol, that sounds like the stuff nightmares are made of, if you are not sure what you're doing $\endgroup$ Commented Aug 18, 2019 at 17:13

3 Answers 3


The reason is to prevent users to mess with it. Unprotecting something is not necessarily dangerous, but unprotecting everything definitely is. Performance is probably not the issue. The real danger is that you replace a very important feature of a built-in symbol by chance. Since built-in symbols often have the ReadProtected attribute, you cannot check beforehand whether you are going to overwrite anything important.

Regarding the appearance of held expressions: One can do this

Format[Hold[a___]] := Held[a];

at the cost of the puzzling results

a = Hold[1 + 1]
a // FullForm

(* Held[2] *)
(* Hold[1 + 1] *)

Internally, the expression should be treated by Mathematica as usual; only the appearance was changed in a counterintuitive way. This particular issue can be fixed by giving the HoldAll attribute to Held:

(* Held[1+1] *)

But still, messing with internals is a very, very bad idea.

Addendum: Mathematica also provides the attribute Locked which prevents changing the Attibutes of a symbol. If that symbol has also the attribute Protected then it cannot be messed with any more. That seems to be the way how developers are meant to protect their users from themselves. However, one cannot rely on the combination Protected and Locked being used consistently for all "important" symbols.

  • $\begingroup$ very nice answer + 1 ! $\endgroup$
    – Ali Hashmi
    Commented Jul 5, 2017 at 12:11

There is a typesetting step after formatting, and MakeBoxes definitions do not require unprotecting Hold, you will just add more DonwValues for MakeBoxes.

MakeBoxes[Hold[a___], fmt_] := With[
    {foo = MakeBoxes[Panel[Column[{a}]], fmt]}
  , InterpretationBox[
        RowBox[{"Hold", "[", foo, "]"}]
      , Hold[a]

Hold[1 + 1, 2 + 2, 4 + 4]

enter image description here

It is always crucial to not let any evaluation leak during typesetting. Here, the content from Hold is passed directly to another MakeBoxes which holds its arguments.

  • 3
    $\begingroup$ It is worth noting that this method does come at the cost of some overhead compared to unprotecting Hold and attaching the formatting to it using TagSet; see: (39675). However in most cases it should not matter and of course +1. $\endgroup$
    – Mr.Wizard
    Commented Jul 4, 2017 at 16:57
  • $\begingroup$ @Mr.Wizard somehow I missed that, thanks! $\endgroup$
    – Kuba
    Commented Jul 5, 2017 at 6:45

The danger when you unprotect things is that there may be unintended side effects. For example, say we unprotect "Plus"...

Plus = Times;

Now if I ask for


Integrate[x^2 + 3, x]

(which is not right at all).

It is very difficult to anticipate all the consequences of unprotecting the meaning of basic symbols.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.