# How to unshadow a chosen definition for a function

I want to use the package NCAlgebra. However after successfully installing the package and trying to write some code, basic functions like

SetNonCommutative[...]


is collored in red with the statement:

A symbol occurs in more than one context: One of the definitions is shadowed.

How can I force Mathematica to use the function from the package?

• Did you quit the kernel and then reload the package? – Jason B. Feb 9 '16 at 9:50
• @JasonB Thanks this resolves the problem! – Anne O'Nyme Feb 9 '16 at 10:05
• Glad to help Anne. – Jason B. Feb 9 '16 at 10:07

Quitting and restarting may not always be the best way to handle shadowing, as it destroys the results of any computations performed. One can also use Remove. From the tutorial Contexts

If you once introduce a symbol that shadows existing symbols, it will continue to do so until you either rearrange $ContextPath, or explicitly remove the symbol. You should realize that it is not sufficient to clear the value of the symbol; you need to actually remove the symbol completely from the Wolfram Language. You can do this using the function Remove[s]. Example. First I Quit[] for a clean start. I then define foo, which creates the symbol Globalfoo. Quit[] foo = 1 (* 1 *)  Now let's say I load a package called "Foo", which creates its own variable foo. Then the following two commands in effect happen somewhere along the way. Foofoo = 2 (* 2 *) AppendTo[$ContextPath, "Foo"]
(*
{"StreamingLoader", "IconizeLoader", "CloudObjectLoader",
"PacletManager", "System", "Global", "Foo"}
*)


At this point foo is shadowed and appears in red.

Let's say that Globalfoo is unnecessary. Then the following removes the shadowing.

Remove["Globalfoo"]


The cells in which foo and Foofoo appeared above now look like this:

Another alternative it is to live with the shadowing and always type Globalfoo for one's own foo. In a properly written package, internal references to the package's foo should always refer to Foofoo. Whether it is more convenient to type the context or remove the symbol and use a different, unshadowed variable name is up to the user.

Related Q&A: