Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question
2  
I confirm this behavior in Mathematica 8.0.4. Undocumented Language`ExtendedDefinition and Language`ExtendedFullDefinition show the same as Defintion. –  Alexey Popkov May 23 '14 at 17:02
    
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 May 23 '14 at 17:30
2  
I 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 May 23 '14 at 19:24

1 Answer 1

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

mySetVar[t]

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

DownValues[mySetVar]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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