This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
How to | Clear My Definitions
When you set a value to a symbol, that value will be used for the symbol for the entire Mathematica session. Since symbols no longer in use can introduce unexpected errors when used in new computations, clearing your definitions is very desirable.
Assign values to two symbols ( and ) and observe their sum:
Click for copyable input
Use Clear to clear the definitions for and :
Click for copyable input
Observe that and no longer have values associated with them and are treated as symbols without definitions:
Click for copyable input
This command clears all the definitions made during the current Mathematica session:
Click for copyable input
Use ClearAll to clear not only the values and definitions of symbols but also the attributes and messages associated with them.
Start with a function to output a range from 0 to some positive integer:
Click for copyable input
Notice that returns an error when a list is given as the argument:
Click for copyable input
Now set to be Listable, so that maps over lists when lists are given as arguments:
Click for copyable input
Notice that after is cleared, the attribute Listable still remains:
Use ClearAll to clear attributes and messages as well:
Use ClearAttributes to clear only the attributes of a function and retain its definition.
Redefine and set it to be Listable as before:
Now use ClearAttributes and notice that while the definition of remains, the Listable attribute is no longer present:
You can also use Unset (=.) to clear any values or definitions made to a symbol:
Click for copyable input
Remove will remove a symbol completely until it is referenced again:
Referring to will bring it back into the Mathematica session:
Click for copyable input
In the case of locally defined symbols, which store values set only for a specified portion of a program, definitions are cleared automatically after use. Symbols can be locally defined by using Block or Module.