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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With