为什么我必须评估两次?

发布于 2024-10-31 17:17:14 字数 574 浏览 0 评论 0原文

我不明白为什么我必须评估两次(在 Mathematica 7 中)才能完成作业。

第一次评估:

Unprotect[Rule];
Attributes[Rule]
pp = Plot | LogLinearPlot | ListPlot | ParametricPlot3D;
(h : pp)[True -> False] ^:= Print["Irrelevant data"]

(*

Out[2]= {SequenceHold}

During evaluation of In[1]:= UpSetDelayed::write: Tag Rule in (h:Plot|LogLinearPlot|ListPlot|ParametricPlot3D)[True->False] is Protected. >>

Out[4]= $Failed

*)

Out[2]= {SequenceHold}可以看出,Unprotect[Rule]有效,但错误消息表明并非如此。如果我第二次评估单元格,则分配成功并且不会生成错误。

为什么会出现这种情况?

I cannot figure out why I have to evaluate this twice (in Mathematica 7) for the assignment to take.

First evaluation:

Unprotect[Rule];
Attributes[Rule]
pp = Plot | LogLinearPlot | ListPlot | ParametricPlot3D;
(h : pp)[True -> False] ^:= Print["Irrelevant data"]

(*

Out[2]= {SequenceHold}

During evaluation of In[1]:= UpSetDelayed::write: Tag Rule in (h:Plot|LogLinearPlot|ListPlot|ParametricPlot3D)[True->False] is Protected. >>

Out[4]= $Failed

*)

As can be seen from Out[2]= {SequenceHold}, Unprotect[Rule] worked, yet the error message indicates otherwise. If I evaluate the cell a second time, the assignment takes and no error is generated.

Why does this happen?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我不会写诗 2024-11-07 17:17:14

您可能很清楚,Mathematica 加载实现其部分功能的二进制 MX 文件。这些 MX 文件存储实现以及定义和属性。

这是阴险的,但您的 Unprotect[Rule] 已被 Mathematica 新加载的 MX 文件撤消,这解释了为什么它第二次起作用。因为 Mathematica 已经加载了它需要的所有 MX 文件。

如果您首先评估表达式中的所有符号,那么它就会停止抱怨:

{Unprotect, Rule, Attributes, Plot, LogLinearPlot, ListPlot, 
  ParametricPlot3D, True, False, Print};
Unprotect[Rule];
Attributes[Rule];
pp = Plot | LogLinearPlot | ListPlot | ParametricPlot3D;
(h : pp)[True -> False] ^:= Print["Irrelevant data"]

编辑在取消保护规则之前,需要第一次评估来触发所有自动加载。

As you might well know, Mathematica loads binary MX files that implement some of its functionality. These MX files store implementations as well as definitions and attributes.

This is insidious, but your Unprotect[Rule] is undone by Mathematica's newly loaded MX file, and this explains why it worked the second time. Because Mathematica had already loaded all MX files it needed.

If you first evaluate all the symbols in your expression, then it stops complaining:

{Unprotect, Rule, Attributes, Plot, LogLinearPlot, ListPlot, 
  ParametricPlot3D, True, False, Print};
Unprotect[Rule];
Attributes[Rule];
pp = Plot | LogLinearPlot | ListPlot | ParametricPlot3D;
(h : pp)[True -> False] ^:= Print["Irrelevant data"]

EDIT The first evaluation is needed to trigger all the auto-loading before you unprotect Rule.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文