是否可以删除“上下文"?从加载的上下文列表[]? [英] Is it possible to delete "context`" from the list of loaded Contexts[]?

查看:47
本文介绍了是否可以删除“上下文"?从加载的上下文列表[]?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以使用 Remove["context`*"] 删除特定上下文中的所有符号.但是是否可以从系统中删除 "context`" 本身,以便它不再出现在 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[]?

推荐答案

据我所知(猜测),一旦上下文变为空(有没有符号).至少,这发生在我的测试中.这是一个:

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

这也可以解释为什么调用 Contexts[] 需要相当多的时间——系统必须检查每个上下文是否为空.无论如何,您的问题的答案似乎很简单 - 删除所有符号,上下文将从 Contexts[] 中删除.这也适用于系统加载的上下文 - 您可以尝试一些(例如 XML'),尽管不用说这至少不是一个好的做法.

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.

这篇关于是否可以删除“上下文"?从加载的上下文列表[]?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆