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.
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
- The pattern patt can be given as a string with metacharacters, as StringExpression[…] or as RegularExpression["regex"]. »
- ClearAll allows abbreviated string patterns containing the following metacharacters:
-
* zero or more characters @ one or more characters, excluding uppercase letters - ClearAll["context`*"] clears all symbols in a particular context. »
- ClearAll["`*"] clears all symbols in the current context. »
- ClearAll does not affect symbols with the attributes Locked or Protected. »
- ClearAll has attribute HoldAll. »
Examples
open all close allBasic Examples (1)
Scope (16)
Symbol Inputs (11)
Clear values of variables (ownvalues):
x = 5;xClearAll[x]xfact[1] = 1;
fact[n_] := n fact[n - 1]fact[3]ClearAll[fact]fact[3]h/:f[h[x_]] := hf[x]f[h[x]]ClearAll[h]f[h[x]]f[x_][y_] := h[x, y]f[x][y]ClearAll[f]f[x][y]Format[kappa] := κkappaClearAll[kappa]kappaSetAttributes[f, Listable];f[{x, y}]ClearAll[f]f[{x, y}]Default[f] = 0;
f[x_.] := x ^ 2f[]ClearAll[f]f[]Options[f] = {opt1 -> def1, opt2 -> def2};OptionValue[f, opt1]ClearAll[f]OptionValue[f, opt1]f::usage = "f[x] gives (x - 1)(x + 1)";Message[f::usage]ClearAll[f]Message[f::usage]a = 5;
f[x_] := x ^ 3f[a]ClearAll[a, f]f[a]Use a combination of symbols and symbol names:
x1 = 1;x2 = 3;x3 = 5;ClearAll[{x1, "x2"}]{x1, x2, x3}Using Patterns (5)
Specify symbols to clear as string patterns:
x1 = 1;x2 = 3;y = 5;ClearAll["x*"]{x1, x2, y}Clear all symbols in the current context:
x1 = 1;x2 = 3;y = 5;ClearAll["`*"]{x1, x2, y}Clear all symbols in a given context:
abc`x1 = 1;abc`x2 = 3;abc`y = 5;ClearAll["abc`*"]{abc`x1, abc`x2, abc`y}Clear all 2-character symbols in the current context using StringExpression:
x1 = 1;x2 = 3;y = 5;ClearAll["`" ~~ _ ~~ _]The symbols x1 and x2 were cleared, but y remains unaffected:
{x1, x2, y}Clear all 3-character symbols in the current context using RegularExpression:
x = 1;yy = 3;zzz = 5;ClearAll[RegularExpression["`..."]]{x, yy, zzz}Applications (2)
Clear any old definitions before making new ones:
ClearAll[fib]fib[1] = fib[2] = 1;
fib[n_] := fib[n] = fib[n - 1] + fib[n - 2]fib[5]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 (6)
ClearAll[pattern] clears the same symbols as ClearAll/@Names[pattern]:
x = 1;y = 2; xy = 3;
ClearAll["x*"];
{x, y, xy}x = 1;y = 2; xy = 3;
ClearAll /@ Names["x*"];
{x, y, xy}Clear does not remove attributes, defaults or options:
SetAttributes[f, Listable];
Default[f] = 0;
Options[f] = {opt1 -> def1, opt2 -> def2};
f[x_.] := x ^ 2Clear[f]Definition[f]Use ClearAll to clear everything:
ClearAll[f]Definition[f]Clear does not remove messages:
f::usage = "f[x] gives (x - 1)(x + 1)";Clear[f]Message[f::usage]Use ClearAll to clear messages:
ClearAll[f]Message[f::usage]ClearAll removes all properties and definitions but leaves the symbol intact:
SetAttributes[f, Listable];
f[x_] := x ^ 2ClearAll[f]? fRemove removes the symbol completely:
Remove[f]? fUse Unset (=.) to clear definitions with a particular left-hand side:
SetAttributes[fact, Listable];
fact[0] = 1;
fact[n_Integer] /; n > 0 := n fact[n - 1]
fact[n_Integer] /; n < 0 := -∞fact[0]=.Definition[fact]Clear all definitions and properties:
ClearAll[fact]Definition[fact]ClearAll has the attribute HoldAll:
Definition[ClearAll]symbol = {"x", "y", "z"};x = 1;y = 3;z = 5;ClearAll[symbol]{symbol, x, y, z}symbol = {"x", "y", "z"};ClearAll[Evaluate[symbol]]{symbol, x, y, z}Possible Issues (3)
Protected symbols cannot be cleared:
x = 5;
Protect[x];ClearAll[x]Use Unprotect to clear definitions of protected symbols:
Unprotect[x];
ClearAll[x]Clear can clear the values and definitions for locked symbols:
f[x_] := x ^ 2;
SetAttributes[f, Locked]Definition[f]Clear[f]Definition[f]ClearAll does not affect locked symbols:
f[x_] := x ^ 2ClearAll[f]Definition[f]When using a pattern without a context mark, all matching symbols on $ContextPath are cleared:
x = 1;y = 2;xy = 3;
ClearAll[_ ~~ _]The symbol xy was cleared, along with attempts to clear several system symbols:
xyUse a pattern with an explicit context mark avoid potentially matching symbols from system or other contexts:
ClearAll["`" ~~ _]Tech Notes
Related Guides
Related Workflows
- Clear Definitions for Symbols and Functions
History
Introduced in 1988 (1.0) | Updated in 2022 (13.2)
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_2026_clearall, author="Wolfram Research", title="{ClearAll}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/ClearAll.html}", note=[Accessed: 10-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_clearall, organization={Wolfram Research}, title={ClearAll}, year={2022}, url={https://reference.wolfram.com/language/ref/ClearAll.html}, note=[Accessed: 10-June-2026]}