Nice example. Thanks for sharing.
Another way I've come across is this one:
// define variable name and variable value. can be $$global or $local
varName = "$$MyVariable";
varValue = "value assigned to the variable";
// Let expression formula
formula = "Let ( var = value ; \"\" )" ];
// evaluate the formula while Substituting the text placeholders in formula with the defined values
Substitute ( formula ; [ "var" ; varName ] ; ["value" ; Quote (varValue) ])
I like that you can split it into chunks this way.
There is also the method to create variables using generic names and using the repetition (which can be calculated) to create a dynamically named and accessible “instance”.
There is a great article on this by the Support Group:
and a custom function to set name/value pairs:
The "Evaluate()" is the tip for these.