Wolfram: Symbol Unset, Clear, Remove
- use
Unsetto remove one specific transformation rule of a Pattern. (pattern can be just a symbol.) - use
Clearto remove all definitions of a symbol. - use
Removeto remove the symbol entirely from the session.
normally, you should just use Clear because that is the most simple.
Unset
Unset-
Unset[pattern]🔸 SHORT SYNTAX:
pattern=.xx=3; Print[xx] (* 3 *) Print[Unset[xx]] (* Null *) Print[xx] (* xx *) (* example of Unset using syntax shortcut *) xx=3; Print[xx] (* 3 *) Print[xx=.] (* Null *) Print[xx] (* xx *) (* example of Unset on a pattern that's not just a symbol *) ff[0] = 3; Print[ff[0]] (* 3 *) Print[ Unset[ff[0]] ] (* Null *) Print[ff[0]] (* ff[0] *)
Clear a Symbol's Value
-
Clear[sym1, sym2, etc] -
Clear the values and definitions of Symbols.
💡 TIP: advanced. Clear does not clear attributes, defaults, options or messages associated with symbols.
xx = 3 (* 3 *) yy = 4 (* 4 *) {xx, yy} (* {3, 4} *) Clear[xx] {xx, yy} (* {xx, 4} *) (* clear multiple variables *) Clear[x1,x2] (* clear all variable starting with x *) Clear["x*"] (* clear all symbols in current context *) (* this is most useful for clearing all user-defined values in current session. *) Names["`*"]
Clear Everything of a Symbol
ClearAll-
ClearAll[symbol1, symbol2, etc]Clear all values, definitions, attributes, defaults, options and messages.
Remove a symbol
Remove-
Remove Symbols from the system.
💡 TIP: you basically never need to remove a symbol. Usually you just need
Clear.