问题
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[]?
回答1:
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.
来源:https://stackoverflow.com/questions/6867575/is-it-possible-to-delete-context-from-the-list-of-loaded-contexts