1

Can anyone explain why the first of these expressions works as expected while the second does not? What is the difference between "number one" and DisplayForm@"number one"?

Block[{$MessagePrePrint}, Message[f::event, DisplayForm@"number one"]]

Block[{$MessagePrePrint}, Message[f::event, "number one"]]
Alexey Popkov
  • 9,355
  • 4
  • 42
  • 93

2 Answers2

2

The error message is a clue:

An unknown box name (Times) was sent as the BoxForm for the expression. Check the format rules for the expression.

I presume $MessagePrePrint is low level, like $PreRead, and its output needs to be a valid box structure.

Mr.Wizard
  • 24,179
  • 5
  • 44
  • 125
  • 1
    So we can use `ToBoxes` instead of `DisplayForm`? – Alexey Popkov Apr 13 '11 at 10:30
  • @Mr.Wizard Doesn't happen on my machine. See my answer. – Sjoerd C. de Vries Apr 13 '11 at 10:34
  • @Alexey, Yes. Again it is hard for me to understand what you are doing, so pardon me if I am trivializing a difficult issue. You can use `Block[{$MessagePrePrint = Automatic} ...` if you just want to temporarily disable a custom `$MessagePrePrint`. – Mr.Wizard Apr 13 '11 at 10:35
  • In really I do not like to change global *Mathematica* settings and use modified functions only *inside* my own where I can control their behavior. In this particular case I just don't see any need in `$MessagePrePrint` inside my function at all. So I disable it. – Alexey Popkov Apr 13 '11 at 10:42
  • 1
    Instead of `"number one"` I write now `"\"number one\""`. It works. :) – Alexey Popkov Apr 13 '11 at 10:49
  • @Alexey If I understand you do not want some other setting to be active inside your own program. Use `$MessagePrePrint = Automatic` to disable an external setting, as according to the help file, that is the default. edit: interesting that you can escape the string delimiters, but I stand by my recommendation. – Mr.Wizard Apr 13 '11 at 10:50
  • @Mr.Wizard: I'm guessing that Alexey is being really careful with all of this because of his work with MathLink... – Simon Apr 13 '11 at 11:18
  • @Mr.Wizard As I have already said I think there is no need for `$MessagePrePrint` inside my program at all. And `$MessagePrePrint = Automatic` I do not need too since I do not know exactly how it works and even in that case I would probably not use it because I just do not need any additional preprocessing of `Message` arguments. – Alexey Popkov Apr 13 '11 at 14:50
  • @Mr.Wizard `"\"number one\""` is just the output of `"number one"//ToBoxes//FullForm`. – Alexey Popkov Apr 13 '11 at 14:55
2

Works on my machine (v8.0.1, W7-64):

enter image description here

Sjoerd C. de Vries
  • 16,122
  • 3
  • 42
  • 94