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.
Remove
does everything thatClearAll
does AND it also removes the "introduction" of that symbol. Am I missing something? $\endgroup$f[a]=1
. Nowf[a]
gives1
;ClearAll[a]
does nothing in practice, asa
had no definitions, attributes, etc. Now tryRemove[a]
and evaluatef[a]
again. $\endgroup$