Maximum number of literal values for SetDelayed?



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 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 as well. Both machines tested are Linux x86-64.

Matthew Titsworth

Posted 2014-05-22T10:53:56.417

Reputation: 605


I confirm this behavior in Mathematica 8.0.4. Undocumented Language`ExtendedDefinition and Language`ExtendedFullDefinition show the same as Defintion.

– Alexey Popkov – 2014-05-23T17:02:11.597

The question is then whether or not this is an intended behavior, to which I would wager "no." If there is a consensus on that, can this be marked as a bug? I will pass it along to Wolfram, reporting back on whatever I get as a response. – Matthew Titsworth – 2014-05-23T17:30:00.547

2I just have checked this in Mathematica 5.2 and behavior is the same. Looks like a bug to me due to inconsistency with the parallel processing functionality. If you wish to mark it as a bug please include in the question some code demonstrating wrong behavior of DistributeDefinitions. It will be interesting to hear the responce from WRI on this issue. – Alexey Popkov – 2014-05-23T19:24:13.283



If you test the code above, i.e. run


it works correctly (i.e. var is set to 20).

The problem is actually one of "Definition" rather than SetDelayed. Definition is a weird function that simply prints some info to the screen. In this case, it gets it wrong, i.e. there is a bug in Definition. As a work around, if you want authoritative information on a symbol, use



Posted 2014-05-22T10:53:56.417

Reputation: 1 483