2
$\begingroup$

Original Question: I used the convert command before loading the Units package.

Convert[20000. Feet, Mile]

Since Convert isn't defined, it returns unevaluated. Now if I load the units package, the function evaluates, but the symbols Convert, Feet, and Mile are highlighted in red by the front-end:

Needs["Units`"]
(* Convert::shdw: Symbol Convert appears in multiple contexts {Units`,Global`}; definitions in context Units` may shadow or be shadowed by other definitions. >> *)

Convert[20000. Feet, Mile]
(* 3.78788 Mile *)

I know I could restart the kernel and load the package, but how else can I proceed at this point to get rid of the shadowed definitions and make everything work properly?

I tried Remove[Convert,Mile,Feet], but then Convert no longer works (expected), then I tried reloading the package, but the command still doesn't work.

Fix for my problem: According to the helpful comments and the answer by @Szabolcs, it seems my mistake was not paying attention to the context of the symbols that were shadowed. The following code shows one way to solve the issue I encountered:

enter image description here enter image description here

$\endgroup$
5
$\begingroup$

You need to use

Remove[Global`Convert]

instead of

Remove[Convert]

Convert is coloured red as a warning because both Units`Convert and Global`Convert exist, so when you simply type Convert one of the two has to be chosen, which might not be the one you wanted.

$\endgroup$
  • $\begingroup$ @Szaboics: That did not seem to work, see my posting at the end of my question. $\endgroup$ – David Nov 27 '14 at 21:47
  • $\begingroup$ @David Actually it does work. I try not to post answers without testing them. What likely happened in your case was that first you Removed Units`Convert (Remove[Convert] does that), and then you removed Global`Convert as well. Then you tried re-loading the package using Needs, which did not have any effect as the package was already loaded. Needs differs from Get precisely in that it doesn't read packages that are already loaded. $\endgroup$ – Szabolcs Nov 27 '14 at 22:06
  • $\begingroup$ Does is make sense to include the differences between Get and Needs in your answer as well? It seems as if they go nicely together with your comments on Remove, making a more canonical answer. $\endgroup$ – bobthechemist Nov 27 '14 at 22:39
  • $\begingroup$ @Szaboics: Your last comment was correct and you can view the results above in my original question under the heading Second Attempt at Fixing the Problem. Thanks for your effort. I've learned a lot. $\endgroup$ – David Nov 27 '14 at 23:35
  • $\begingroup$ @David If you accidentally remove Units`Convert, you can re-load the package using <<Units` . This only differs from Needs["Units`"] in that it doesn't have a re-load protection. $\endgroup$ – Szabolcs Nov 28 '14 at 0:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.