Unprotect
Details
- A typical sequence in adding your own rules for built‐in functions is Unprotect[f];definition;Protect[f]. »
- The pattern patt can be given as a string with metacharacters, as StringExpression[…] or as RegularExpression["regex"]. »
- Unprotect allows abbreviated string patterns containing the following metacharacters:
-
* zero or more characters @ one or more characters, excluding uppercase letters - Unprotect["context`*"] unprotects all symbols in a particular context. »
- Unprotect["`*"] unprotects all symbols in the current context. »
- Unprotect does not affect symbols with the attribute Locked. »
- Unprotect has attribute HoldAll. »
Examples
open all close allBasic Examples (1)
Scope (7)
Symbol Inputs (2)
Protect[f, g, h];Attributes[{f, g, h}]Unprotect[f, g, h]Attributes[{f, g, h}]Use a combination of symbols and symbol names:
Protect[x1, x2, x3];Unprotect[{x1, "x2"}]Attributes[{x1, x2, x3}]Using Patterns (5)
Specify symbols to unprotect as string patterns:
Protect[x1, x2, y];Unprotect["x*"]Attributes[{x1, x2, y}]Unprotect all symbols in the current context:
Protect[x1, x2, x3];Unprotect["`*"]Attributes[{x1, x2, x3}]Unprotect all symbols in a given context:
Protect[abc`x1, abc`x2, abc`y];Unprotect["abc`*"]Attributes[{abc`x1, abc`x2, abc`y}]Unprotect all 2-character symbols in the current context using StringExpression:
Protect[x1, x2, y];Unprotect["`" ~~ _ ~~ _]The symbols x1 and x2 were unprotected, but y remains unaffected:
Attributes[{x1, x2, y}]Unprotect all 3-character symbols in the current context using RegularExpression:
Protect[x, yy, zzz];Unprotect[RegularExpression["`..."]]Attributes[{x, yy, zzz}]Applications (2)
Unprotect a system symbol to make a definition for it:
protected = Unprotect[Sqrt]Sqrt[x_ ^ 2] := xSqrt[x ^ 2]Protect[Evaluate[protected]]Unprotect and clear all symbols in a package, to allow it to be read twice:
Begin["`Private`"];Unprotect["`*"];
ClearAll["`*"];f[x_] := x ^ 2Protect[f];End[];Properties & Relations (7)
Unprotect[pattern] unprotects the same symbols as Unprotect/@Names[pattern]:
Protect[x, y, xy];
Unprotect["x*"];
Attributes[{x, y, xy}]Protect["x*"];
Unprotect /@ Names["x*"];
Attributes[{x, y, xy}]Protecting a symbol is equivalent to setting the Protected attribute:
Protect[f];
SetAttributes[g, Protected];Attributes[{f, g}]Unprotecting a symbol is equivalent to clearing the Protected attribute:
Unprotect[f];
ClearAttributes[g, Protected];Attributes[{f, g}]Unprotecting a symbol does not clear other attributes:
SetAttributes[f, {HoldFirst, Protected}];Unprotect[f]Attributes[f]Unprotect returns the list of symbols actually unprotected:
Protect[f, g];Unprotect[f]If a symbol is already unprotected, it is not unprotected again:
Unprotect[f, g]No more definitions can be made for a protected symbol:
f[x_] := x ^ 2;
Protect[f];f[x_] := x ^ 3To modify definitions of a protected symbol, unprotect it first:
Unprotect[f];f[x_] := x ^ 3Unprotect has the attribute HoldAll:
Definition[Unprotect]This unprotects symbol itself:
symbol = {f, g, h};Protect /@ symbol;Protect[symbol];Unprotect[symbol]Attributes[{symbol, f, g, h}]Protect[symbol];Unprotect[Evaluate[symbol]]Attributes[{symbol, f, g, h}]Unprotect accepts any number of arguments, including zero:
Unprotect[]Possible Issues (2)
Unprotect does not affect locked symbols:
SetAttributes[f, {Locked, Protected}]Unprotect[f]Definition[f]When using a pattern without a context mark, all matching symbols on $ContextPath are unprotected:
Protect[x, y, xy];
Unprotect[_ ~~ _]The symbol xy was unprotected, along with several system symbols:
Attributes[xy]Use a pattern with an explicit context mark to avoid potentially matching symbols from system or other contexts:
Unprotect["`" ~~ _]Reprotect the system symbols that were wrongly unprotected:
Protect["System`" ~~ _ ~~ _]Tech Notes
Related Guides
History
Introduced in 1988 (1.0) | Updated in 2022 (13.2)
Text
Wolfram Research (1988), Unprotect, Wolfram Language function, https://reference.wolfram.com/language/ref/Unprotect.html (updated 2022).
CMS
Wolfram Language. 1988. "Unprotect." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2022. https://reference.wolfram.com/language/ref/Unprotect.html.
APA
Wolfram Language. (1988). Unprotect. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Unprotect.html
BibTeX
@misc{reference.wolfram_2026_unprotect, author="Wolfram Research", title="{Unprotect}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/Unprotect.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_unprotect, organization={Wolfram Research}, title={Unprotect}, year={2022}, url={https://reference.wolfram.com/language/ref/Unprotect.html}, note=[Accessed: 13-June-2026]}