An example of the problem I am encountering:
choices = {"A", "B", "C", "D", "E"};
buttons = {};
callMe[n_] := Module[{}, MessageDialog[choices[n]]];
test[] := Module[{},
buttons = {};
Scan[AppendTo[buttons, Button[#, callMe[Length@buttons + 1]]] &, choices];
Return@buttons;
];
test[]
The call to test displays a list of buttons. When I click on one of these, I want the 'n_' argument to 'callMe' to contain the index into 'choices' from which that button got its caption. But this is not what happens. n_ is always equal to 6 (the last value of 'Length@buttons+1'), no matter which button is clicked. I've tried various combinations of ReleaseHold, Evaluate, etc. This is most likely quite simple, but I can't get anything to work. Can someone point me in the right direction?
Attributesof functions lead more than often to unexpected behavior. Would you go ahead and post an answer to your question? – halirutan Jun 10 '18 at 01:41