Unprotect

Unprotect[s1,s2,]

removes the attribute Protected for the symbols si.

Unprotect[patt1,patt2,]

unprotects all symbols whose names textually match any of the arbitrary string patterns patti.

Unprotect[{spec1,spec2,}]

unprotects any symbols that are equal to or whose names match any of the speci.

Details

  • A typical sequence in adding your own rules for builtin 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 allclose all

Basic Examples  (1)

Default behavior:

Unprotect and modify the definition:

New behavior:

Scope  (7)

Symbol Inputs  (2)

Unprotect several symbols:

Use a combination of symbols and symbol names:

Only x3 remains protected:

Using Patterns  (5)

Specify symbols to unprotect as string patterns:

Unprotect all symbols in the current context:

Unprotect all symbols in a given context:

Unprotect all 2-character symbols in the current context using StringExpression:

The symbols x1 and x2 were unprotected, but y remains unaffected:

Unprotect all 3-character symbols in the current context using RegularExpression:

Applications  (2)

Unprotect a system symbol to make a definition for it:

Restore protection:

Unprotect and clear all symbols in a package, to allow it to be read twice:

Properties & Relations  (6)

Unprotect[pattern] unprotects the same symbols as Unprotect/@Names[pattern]:

Protecting a symbol is equivalent to setting the Protected attribute:

Unprotecting a symbol is equivalent to clearing the Protected attribute:

Unprotecting a symbol does not clear other attributes:

Unprotect returns the list of symbols actually unprotected:

If a symbol is already unprotected, it is not unprotected again:

No more definitions can be made for a protected symbol:

To modify definitions of a protected symbol, unprotect it first:

Unprotect has the attribute HoldAll:

This unprotects symbol itself:

This unprotects its value:

Possible Issues  (2)

Unprotect does not affect locked symbols:

When using a pattern without a context mark, all matching symbols on $ContextPath are unprotected:

The symbol xy was unprotected, along with several system symbols:

Use a pattern with an explicit context mark to avoid potentially matching symbols from system or other contexts:

Reprotect the system symbols that were wrongly unprotected:

Wolfram Research (1988), Unprotect, Wolfram Language function, https://reference.wolfram.com/language/ref/Unprotect.html (updated 2022).

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_2024_unprotect, author="Wolfram Research", title="{Unprotect}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/Unprotect.html}", note=[Accessed: 21-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_unprotect, organization={Wolfram Research}, title={Unprotect}, year={2022}, url={https://reference.wolfram.com/language/ref/Unprotect.html}, note=[Accessed: 21-November-2024 ]}