# Is it safe to Unprotect everything? What are the implications?

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?

• You can also assign values to Format if you are just interested in appearance. – LLlAMnYP Jul 3 '17 at 16:25
• No, it is not safe to Unprotect everything. The implication is more bugs in your code and wasting your time finding them. – Nasser Jul 3 '17 at 16:47
• You should edit this question to focus it on real problem: changing the appearance of held expressions. – m_goldberg Jul 3 '17 at 19:04
• 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 – yosimitsu kodanuri Aug 18 at 17:13

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

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


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:

SetAttributes[Held,HoldAll]
a
(* 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.

• very nice answer + 1 ! – Ali Hashmi Jul 5 '17 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]


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.

• 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. – Mr.Wizard Jul 4 '17 at 16:57
• @Mr.Wizard somehow I missed that, thanks! – Kuba Jul 5 '17 at 6:45

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

Unprotect[Plus];
Plus = Times;


5+4