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

独自空忆成欢 提交于 2019-12-22 04:17:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!