Remove

Remove[s1,s2,]

removes the symbols si completely, so that their names are no longer recognized by the Wolfram Language.

Remove[patt1,patt2,]

removes all symbols whose names textually match any of the arbitrary string patterns patti.

Remove[{spec1,spec2,}]

removes any symbols that are equal to or whose names match any of the speci.

Details

  • You can use Remove to get rid of symbols that you do not need, and which may shadow symbols in contexts later on your context path. »
  • The pattern patt can be given as a string with metacharacters, as StringExpression[] or as RegularExpression["regex"]. »
  • Remove allows abbreviated string patterns containing the following metacharacters:
  • *match zero or more characters
    @match one or more characters, but not uppercase letters
  • Remove["context`*"] removes all symbols in a particular context. »
  • Remove["`*"] removes all symbols in the current context. »
  • Once you have removed a symbol, you will never be able to refer to it again, unless you recreate it.
  • If you have an expression that contains a symbol that you remove, the removed symbol will be printed as Removed["name"], where its name is given in a string. »
  • Remove works with LocalSymbol, CloudSymbol, PersistentSymbol and InitializationValue objects. »
  • Remove does not affect symbols with the attributes Locked or Protected. »
  • Remove has attribute HoldAll. »

Examples

open allclose all

Basic Examples  (1)

Define a symbol:

Remove the symbol:

The symbol has been removed from the system:

Scope  (11)

Symbol Inputs  (2)

Remove several symbols:

They are no longer recognized as valid names:

Use a combination of symbols and symbol names:

Only x3 remains known to the system:

Using Patterns  (5)

Specify symbols to remove as string patterns:

Remove all symbols in the current context:

There are no longer any symbols in the current context:

Remove all symbols in a given context:

Remove all 2-character symbols in the current context using StringExpression:

The symbols x1 and x2 were removed, but y remains unaffected:

Remove all 3-character symbols in the current context using RegularExpression:

Symbol-like Objects  (4)

Remove a local symbol:

Remove a cloud symbol:

Remove a persistent symbol:

Remove initialization values for a symbol:

Applications  (1)

If a symbol from a package is used before the package is loaded, an extra symbol is created:

The extra symbol in the current context should be removed:

Only the correct symbol from the package remains:

Properties & Relations  (5)

Remove[pattern] removes the same symbols as Remove/@Names[pattern]:

If a symbol is removed, all of its properties and definitions are removed as well:

Using the same symbol again creates a new one without any of its old properties:

ClearAll also removes all properties and definitions but leaves the symbol intact:

Remove removes the symbol completely:

If an expression still refers to a removed symbol, those places are denoted with Removed:

Remove has the attribute HoldAll:

This removes symbol itself:

This removes its value:

Possible Issues  (3)

Protected symbols cannot be removed:

Use Unprotect to remove protected symbols:

Remove does not affected locked symbols:

When using a pattern without a context mark, all matching symbols on $ContextPath are removed:

The symbol xy was removed, along with attempts to remove several system symbols:

Use a pattern with an explicit context mark to avoid potentially matching symbols from system or other contexts:

Wolfram Research (1988), Remove, Wolfram Language function, https://reference.wolfram.com/language/ref/Remove.html (updated 2022).

Text

Wolfram Research (1988), Remove, Wolfram Language function, https://reference.wolfram.com/language/ref/Remove.html (updated 2022).

CMS

Wolfram Language. 1988. "Remove." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2022. https://reference.wolfram.com/language/ref/Remove.html.

APA

Wolfram Language. (1988). Remove. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Remove.html

BibTeX

@misc{reference.wolfram_2023_remove, author="Wolfram Research", title="{Remove}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/Remove.html}", note=[Accessed: 18-March-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_remove, organization={Wolfram Research}, title={Remove}, year={2022}, url={https://reference.wolfram.com/language/ref/Remove.html}, note=[Accessed: 18-March-2024 ]}