# Remove versus ClearAll

What is the difference between Remove and ClearAll?

I thought that "not being recognized by Mathematica", which is the effect of Remove, meant that there would be no "values, definitions, attributes, messages, and defaults associated with symbols", which is the effect of ClearAll. That naive equivalence is wrong as shown by the different output out of these two lines:

b := a; Remove[a]; b
b := a; ClearAll[a]; b


Which side effects of Remove are not shared by ClearAll (and viceversa)?

• Related: How do I clear all user defined symbols?, especially rm-rf's answer. Commented Nov 22, 2013 at 17:57
• It seems that a symbol is "introduced" when it is first used, even if it is only as rhs. "introduction" not being the same as "definition", which I understand as including an OwnValue, DownValue, etc. With this distinction, Remove does everything that ClearAll does AND it also removes the "introduction" of that symbol. Am I missing something? Commented Nov 22, 2013 at 18:12
• Remove removes the symbol, ClearAll does not. Commented Nov 22, 2013 at 18:17
• Here's a practical difference: f[a]=1. Now f[a] gives 1; ClearAll[a] does nothing in practice, as a had no definitions, attributes, etc. Now try Remove[a] and evaluate f[a] again. Commented Nov 22, 2013 at 18:49
• Read also this. Commented Nov 22, 2013 at 19:03

ClearAll clears all definitions associated with the symbol. However, the symbol remains in the symbol table, so all references to that symbol from other symbols (their definitions) remain fully valid. The symbol can then acquire new rules or other global properties associated with it.

Remove removes the symbol from the symbol table. More precisely, it removes the association between the symbol name and the actual symbol. In any case, the symbol becomes unusable (normally. There are ways to still use it, will mention that below). The same is true for all references to that symbol from other symbols, which silently become invalid. What this means is that by using Remove, one can subtly invalidate the code in ways which will be very hard to track (but see the link below for some suggestions here). For more details on certain interesting properties of Remove-d symbols, I refer to this discussion.

In terms of their usage, the two functions are quite different. ClearAll is a function intended for quite frequent and general use. Remove, however, I view as a much more specialist and lower-level function. In fact, I would advise against using Remove unless you know exactly what you are doing. It does have a number of advanced uses, but normally the only use which comes to mind is to remove an accidental shadow symbol during the interactive work.

Besides destroying the symbol itself, the main side effect of Remove that is not shared by ClearAll is what happens to expressions containing a removed symbol.

a = {x, y};
ClearAll[x, y];a

{x, y}

Remove[y]; a

{x, Removed[y]}