Under what circumstances should I expect Mathematica to turn a delayed assignment into an immediate assignment? I have put together a minimal example (available here) which demonstrates this behavior. There is a package which contains basically the following, where each line has its own cell in the notebook from which the package is generated:
setMyVar[a] := (var = 1;) setMyVar[b] := (var = 2;) setMyVar[c] := (var = 3;) setMyVar[d] := (var = 4;) setMyVar[e] := (var = 5;) setMyVar[f] := (var = 6;) setMyVar[g] := (var = 7;) setMyVar[h] := (var = 8;) setMyVar[i] := (var = 9;) setMyVar[j] := (var = 10;) setMyVar[k] := (var = 11;) setMyVar[l] := (var = 12;) setMyVar[m] := (var = 13;) setMyVar[n] := (var = 14;) setMyVar[o] := (var = 15;) setMyVar[p] := (var = 16;) setMyVar[q] := (var = 17;) setMyVar[r] := (var = 18;) setMyVar[s] := (var = 19;) setMyVar[t] := (var = 20;)
When I load this package and then evaluate
Definition[setMyVar] every assignment is defined as a
Set rather than a
SetDelayed in Mathematica 188.8.131.52. However if I comment out any three of these, everything returns to being
SetDelayed. Does anyone have any idea why Mathematica would do this? If so, is there a system variable I can change to address this problem? The tarball also contains a notebook which demonstrates the behavior in a setting which is not loaded from a package.
This does not come up if everything is in a single cell, but arranging everything in such a way is not practical for the actual application in which I ran across this. To address why this might be considered to be a problem, I ran across this while using
DistributeDefinitions["Context"] which as stated in the documentation essentially runs
ParallelEvaluate on every statement in the context, and this is causing things to be evaluated which should not be.
Edit to add: I have confirmed that this occurs with Mathematica 184.108.40.206 as well. Both machines tested are Linux x86-64.