3
$\begingroup$

I'm just going crazy with Mathematica Contexts as they absolute do not work as intended.

Simple Example:

Begin["TEST`"]
Hello[s_]:=s
Bye[s_]:=s
End[]

Now using TEST`Hello works:

TEST`Hello["test"]
test

The names of context TEST are:

Names["TEST`*"]
{"TEST`Bye", "TEST`Hello"}

Now I want to remove the Bye function as it is no longer needed:

Clear["TEST`Bye"]
Names["TEST`*"]
{"TEST`Bye", "TEST`Hello"}

But its still there. Let's try to clear everything:

ClearAll["TEST`*"]
Names["TEST`*"]
{"TEST`Bye", "TEST`Hello"}

Still everything is there! The same goes for packages and as Mathematica happily shares the kernels by default it's basically impossible for me to develop independent code because of thousands of shadowing warnings etc.

So my questions are:

  1. How can I clear a context or package?
  2. What is your workflow in developing individual Mathematica packages that are independent of each other and can be loaded on demand?

Update:

  1. Obviously use Remove instead of Clear. Thanks to the commentators.
  2. Have a look at Creating Mathematica Packages
$\endgroup$

closed as off-topic by MarcoB, ilian, m_goldberg, Bob Hanlon, Öskå Aug 8 '15 at 9:03

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – MarcoB, ilian, m_goldberg, Bob Hanlon, Öskå
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 5
    $\begingroup$ You can use Remove[TEST'Bye]. $\endgroup$ – Marius Ladegård Meyer Aug 7 '15 at 17:20
  • $\begingroup$ From the docs, Clear clears values and definitions for symbols, but it does not remove the symbols themselves. That is what Remove is for. Also, it seems to me that the second part of your question is almost entirely separate from the first. You may want to take a look at the previous discussion on Creating Mathematica Packages. $\endgroup$ – MarcoB Aug 7 '15 at 17:49
  • $\begingroup$ Thanks you very much, I only knew about Clear. Remove is exactly what I want, thanks. This answers part 1. of my questions. How do you deal with 2.? $\endgroup$ – Thomas Fankhauser Aug 7 '15 at 17:53