在 Mathematica 中查找先前定义的消息
Mathematica 默认定义了许多有用的消息来指示常见错误,例如使用错误数量的参数调用函数或未找到文件。一般来说,我更喜欢尽可能使用现有的、已定义的消息,因为这样可以更轻松地通过 Check
、Quiet
和 On< 等机制处理它们。 /code>/
关闭
。然而,我所有寻找当前定义的消息的尝试都失败了;明显的方法
DownValues[MessageName]
根本不起作用。
我缺少什么技巧吗?
提前致谢。
Mathematica by default defines a lot of useful messages for signaling common errors, like functions being called with the wrong number of arguments or files not being found. In general, I prefer to use existing, defined messages wherever possible, because it makes it easier for them to be handled via mechanisms like Check
, Quiet
and On
/Off
. However, all my attempts at finding what messages are currently defined have failed; obvious approaches like
DownValues[MessageName]
don't work at all.
Is there a trick I'm missing?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是个好问题。原则上,您可以使用
Messages[]
显示与符号关联的任何消息。但是,根据文档,系统消息只有在实际使用时才会加载。但是,$MessageGroups(7 中新增)确实提供了一些可用消息的列表,但不是几乎全部。编辑:经过一番查看,我发现文件
$InstallationDirectory/SystemFiles/Kernel/TextResources/English/Messages.m
似乎包含所有系统范围的消息。That's a good question. In principle, you can display any messages associated with a symbol by using
Messages[<symbol>]
. However, according to the documentation, the system messages are not loaded until the message is actually used. But,$MessageGroups
(new in 7) does provide a list of some of the messages available, but not nearly all.EDIT: After some looking, I found the file
$InstallationDirectory/SystemFiles/Kernel/TextResources/English/Messages.m
that appears to contain all of the system wide messages.