2
$\begingroup$

Why does

1/0
$MessageList
ComplexInfinity

whereas

Block[{},
1/0;
$MessageList
]
Power::infy

?

At first sight I supposed that this disparity could be related to an answer I got here subtleties about variable shadowing in Block[] "Symbols are created at the instant that they are read -- not when they are evaluated.". But, may be, this time we are facing a totally different problem because $MessageList exists rigth before Block[] is read.

Have I missed some point explained in Messages leak out from Block ?

Thanks once more !!

$\endgroup$
3
  • $\begingroup$ Not sure what do you expect, Block has nothing to do with this, try 1/ 0; $MessageList.Or have I missed something? $\endgroup$
    – Kuba
    Commented Mar 30, 2015 at 10:13
  • $\begingroup$ I expect the same message (Power::infy or ComplexInfinity) in both situations. $\endgroup$ Commented Mar 30, 2015 at 12:27
  • $\begingroup$ You should not, you have CompoundExpression in Block and two separate lines in first code area. $MessageList remembers only current execution line $\endgroup$
    – Kuba
    Commented Mar 30, 2015 at 12:29

1 Answer 1

5
$\begingroup$

$MessageList is a global variable that gives a list of the names of messages generated during the evaluation of the current input line.

The confusion is probably due to the wording, in reality Wolfram System reads expression by expression but not less than one line. See How parsing works, more or less.

Those are two separate inputs

1/0
$MessageList

while this is one input, the first line is not a full expression, MMA has to read more:

Block[{},
  1/0;
  $MessageList
]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.