为什么我必须评估两次?
我不明白为什么我必须评估两次(在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能很清楚,Mathematica 加载实现其部分功能的二进制 MX 文件。这些 MX 文件存储实现以及定义和属性。
这是阴险的,但您的
Unprotect[Rule]
已被 Mathematica 新加载的 MX 文件撤消,这解释了为什么它第二次起作用。因为 Mathematica 已经加载了它需要的所有 MX 文件。如果您首先评估表达式中的所有符号,那么它就会停止抱怨:
编辑在取消保护
规则
之前,需要第一次评估来触发所有自动加载。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:
EDIT The first evaluation is needed to trigger all the auto-loading before you unprotect
Rule
.