Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to delete "context`" from the list of loaded Contexts[]?

We can remove all symbols in a particular context by using Remove["context`*"]. But is it possible to remove "context`" itself from the system so that it will no longer be listed in Contexts[]?

like image 892
Alexey Popkov Avatar asked Jul 29 '11 01:07

Alexey Popkov


1 Answers

As far as I can tell (a guess), a context is automatically removed from Contexts[] once it becomes empty (has no symbols). At least, this happens in my tests. Here is one:

In[1]:= 
BeginPackage["Test`"]
EndPackage[]

Out[1]= Test`

In[3]:= MemberQ[Contexts[],"Test`"]
Out[3]= False

In[4]:= Test`a
Out[4]= a

In[5]:= MemberQ[Contexts[],"Test`"]
Out[5]= True

In[6]:= Remove["Test`*"]
In[7]:= MemberQ[Contexts[],"Test`"]

Out[7]= False

This may also explain why calling Contexts[] takes a sizable fraction of a second - the system must check for every context whether or not it is empty. Anyways, the answer to your question seems simple - remove all symbols and the context will be removed from Contexts[]. This also works for contexts loaded by the system - you may try some (XML' for example), although needless to say this is not a good practice, to say the least.

like image 96
Leonid Shifrin Avatar answered Oct 30 '22 10:10

Leonid Shifrin