On Saturday, September 13, 2014 6:47:46 PM UTC-5, [email protected] wrote:
>
> However, suppose the field that has to be changed is determined by the
> program. Say, I have,
>
> varToChange = "numLines"
>
> How can I use *varToChange* to change the value of *numLines* in *inst*?
>
Here are a couple of alternatives.
Depending on the source of your "numLines", you can assign the symbol
directly, rather than via a string and a call to symbol(), combining it
with either Don or Isaiah's syntaxes:
varToChange = :numLines
If this is the sort of thing you find you are doing often, a composite type
may not be the correct data structure for your application. Consider a Dict:
inst = Dict{String, Any}()
inst["numLines"] = 10
inst["avgLength"] = 8.5
inst[varToChange] = 20
Patrick