Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to construct a list of Set's

I have a large set of parameters P which take several distinct sets of values V_i and want to use ActionMenu[] to make assigning P=V_i easy, like so:

ActionMenu["Label", {"name_1" :> (P = V_1;),..}]

Now the problem is that the set of V_i's is large and not static, so instead of coding a long list {"opt_1" :> (P = V_1;),..} over and over by hand, I'd like to generate it.

I am completely stumped at how to do it. The general approach is something like

Thread@RuleDelayed[listOfNames,listOfActions]

where listOfActions should be something like

Thread@Set[repeatedListOfP,listOfV_i]

But this does not work. And since Set[] is a very special function, none of my other usual approaches work (building a Table[], replacing headers, etc). How do you go about constructing a list of Set[] operations?

like image 427
Timo Avatar asked Sep 05 '25 11:09

Timo


1 Answers

There may be more to your question that I haven't grokked yet but maybe this will get you on the right track.

This

MapThread[Hold[#1 = #2]&, {{a, b, c}, {1, 2, 3}}]

returns a list of unevaluated "Set"s like so:

{Hold[a = 1], Hold[b = 2], Hold[c = 3]}

If you call ReleaseHold on the above then the assignments will actually happen.

More on Hold and relatives here:
Mathematica: Unevaluated vs Defer vs Hold vs HoldForm vs HoldAllComplete vs etc etc

like image 138
dreeves Avatar answered Sep 11 '25 05:09

dreeves