4

Bug introduced in 10.4.1 or earlier and persisting through 11.1.0 or later


Using x++ or x=x+1 inside Defer generates strange results.

Evaluating the following commands one by one (in three different input cells), with Shift+Enter, one gets:

x=1;
Defer[x++]; 
x
(* 15 but I have also seen 17! *)

Even stranger, if one creates a notebook with only those same commands, restarts the kernel, and does Evaluation ► Evaluate Notebook then the command x returns 1 instead of 15.

Any explanations?

Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368
Soldalma
  • 1,289
  • 1
  • 9
  • 17
  • I get 1 everytime, as I would expect... – ktm Oct 08 '16 at 22:17
  • Same for me, 1 everytime. – anderstood Oct 08 '16 at 22:26
  • 7
  • @user6014 - I forgot to mention that the three commands must be in different cells. (How could I show that in my post?) If they are in the same cell you indeed get 1 every time. – Soldalma Oct 09 '16 at 11:02
  • 4
    @Mr.Wizard - Turning off the Suggestions Bar fixes the problem. Thanks. – Soldalma Oct 09 '16 at 11:03
  • @FernandoSaldanha Just say that they must be in different cells. I edited the post to make them appear in 3 code blocks (see the markdown source to learn how). Please report this bug to Wolfram Support. – Szabolcs Oct 09 '16 at 12:46
  • 2
    @Mr.Wizard What do we do with questions like this? Close it as a duplicate of what you linked? Close it as a duplicate of another question about a Suggestion Bar bug? Post an answer? I'm really disturbed by the amount of problems the Suggestion Bar causes. I think it says more about how difficult it is to manipulate code in Mathematica than about WRI quality control. I would never have dared to attempt to implement something like this myself—the risk of evaluation leaks is much too great. – Szabolcs Oct 09 '16 at 12:50
  • 1
    @Szabolcs - I reported the bug. – Soldalma Oct 09 '16 at 18:27
  • I'm not convinced this is a bug. The documentation is a bit less detailed than might be desired, but Defer does not strike me as a bullet-proof way to prevent any and all internal evaluation. – Daniel Lichtblau Mar 19 '17 at 15:12

0 Answers0