# How to use Set correctly

My codes are shown in the picture attached.

I'm writing codes for numerical calculations frequently, and I think it looks neat and clear to organize input parameters in the form of table. For example,

calcTable=Grid[{{gridNum, tWindow, calcStepPerStep, dataSavingStep},
{8192, 200.*tPulse, 32, 32}}, Dividers -> All]

MapThread[Set, {#[[1, 1]], #[[1, 2]]}] & @ calcTable;


This would be displayed in a form of table in the frontend, and I can easily check and change every parameter.

However, if I want change some of the parameters displayed in the table after I have run the program once, warning appears, and no change of the values can be observed.

I think there must be some misunderstanding in the usage of Set in the MapThread. It can be seen that during the evalutation of

 MapThread[Set, {#[[1, 1]], #[[1, 2]]}] & @
calcTable;


parameters such as {gridNum, tWindow, calcStepPerStep, dataSavingStep} has been assigned with its value at the first place.

Actually, I'd like the evaluation performed in this way, first take {gridNum, tWindow, calcStepPerStep, dataSavingStep} literrally, then use Set to assigned values to them by MapThread. I think this is closely related to nonstandard evaluation. But how can I achieve this?

Thank you very much.

• closely related: 103263 and a possible duplicate: 84284.
– Kuba
Jun 15, 2016 at 12:58

Fundamentally this is a very common question:

The defined Symbols are evaluating before Set ever sees them.

I would need to see how you are actually using this to make a proper recommendation but for the single example given you might wrap the entire thing in HoldForm and Apply the Set like this:

calcTable =
Grid[
{{gridNum, tWindow, calcStepPerStep, dataSavingStep}, {8192, 200.*tPulse, 32, 32}},
Dividers -> All
] // HoldForm

Set @@@ calcTable[[{1}, 1]] // ReleaseHold


You can redefine the Symbols with a second table:

calcTable2 =
Grid[
{{gridNum, tWindow, calcStepPerStep, dataSavingStep}, {foo, bar, 3.14, 42}},
Dividers -> All
] // HoldForm

Set @@@ calcTable2[[{1}, 1]] // ReleaseHold


The Symbols have the new definitions:

{gridNum, tWindow, calcStepPerStep, dataSavingStep}

{foo, bar, 3.14, 42}


I find this a rather clumsy way to handle Symbol assignment however and I imagine that a different approach will ultimately be superior. (Please see the referenced Q&A's for examples.)