Skip to content

ClearAll

Status: Stable

documented, exercised by the test suite and/or worked examples, with no known limitations recorded.

Description

ClearAll[s1, s2, ...]

clears all values, definitions, attributes and messages for the named symbols. ClearAll[{s1, s2, ...}] accepts a list of specs.

Notes ClearAll has attribute HoldAll; symbols with attribute Locked or Protected are not affected.

Examples (3)

Every input below was run against the current Mathilda build and its output recorded.

Basic examples (3)

In[1]:= f[x_] := x^2; SetAttributes[f, Listable]; Attributes[f]
Out[1]= {Listable}

In[2]:= ClearAll[f]; {Attributes[f], DownValues[f]}
Out[2]= {{}, {}}

In[3]:= x = 2; Remove[x]; x
Out[3]= x

Implementation notes

  • ClearAll has attributes {HoldAll, Protected}; Remove has {HoldAll, Locked, Protected}. Both hold their arguments, so they operate on the symbol, not its current value.
  • Neither affects symbols with the attribute Locked or Protected. This is what prevents Remove/ClearAll from ever deleting or wiping a built-in.
  • ClearAll, unlike Clear, also removes attributes and the usage message.
  • Both return Null.

Attributes: HoldAll, Protected.

References

See also: Remove, Clear