ClearAll

ClearAll[s1,s2,]

clears all values, definitions, attributes, defaults, options and messages for the symbols si.

ClearAll[patt1,patt2,]

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

ClearAll[{spec1,spec,}]

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

Details

Examples

open allclose all

Basic Examples  (1)

Define values and attributes for a symbol:

Clear values and attributes:

Scope  (16)

Symbol Inputs  (11)

Clear values of variables (ownvalues):

Clear functions (downvalues):

Clear upvalues:

Clear subvalues:

Clear formatting:

Clear attributes:

Clear defaults:

Clear options:

Clear messages:

Clear several symbols:

Use a combination of symbols and symbol names:

Only x3 remains defined:

Using Patterns  (5)

Specify symbols to clear as string patterns:

Clear all symbols in the current context:

Clear all symbols in a given context:

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

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

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

Applications  (2)

Clear any old definitions before making new ones:

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

Properties & Relations  (6)

ClearAll[pattern] clears the same symbols as ClearAll/@Names[pattern]:

Clear does not remove attributes, defaults or options:

Use ClearAll to clear everything:

Clear does not remove messages:

Use ClearAll to clear messages:

ClearAll removes all properties and definitions but leaves the symbol intact:

Remove removes the symbol completely:

Use Unset (=.) to clear definitions with a particular left-hand side:

Clear all definitions and properties:

ClearAll has the attribute HoldAll:

This clears symbol itself:

This clears its value:

Possible Issues  (3)

Protected symbols cannot be cleared:

Use Unprotect to clear definitions of protected symbols:

Clear can clear the values and definitions for locked symbols:

ClearAll does not affect locked symbols:

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

The symbol xy was cleared, along with attempts to clear several system symbols:

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

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

Text

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

CMS

Wolfram Language. 1988. "ClearAll." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2022. https://reference.wolfram.com/language/ref/ClearAll.html.

APA

Wolfram Language. (1988). ClearAll. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ClearAll.html

BibTeX

@misc{reference.wolfram_2023_clearall, author="Wolfram Research", title="{ClearAll}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/ClearAll.html}", note=[Accessed: 19-March-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_clearall, organization={Wolfram Research}, title={ClearAll}, year={2022}, url={https://reference.wolfram.com/language/ref/ClearAll.html}, note=[Accessed: 19-March-2024 ]}