[erlang-questions] Dynamically access record fields
Sun Feb 10 02:02:12 CET 2013
On 9 February 2013 23:57, Dmitry Kolesnikov <> wrote:
> What I was saying was that you can't do something like
> Field = a,
> V2 = setelement(#foo.Field, V1, "A+")
> but you can do
> Field = #foo.a,
> V2 = setelement(Field, V1, "A+")
> and do not see any difference, isn't it?
> - Dmitry
Well yes there is.
What I think Jeremy wants is to dynamically concatenate record names,
which is as you know
impossible due to record names being resolve at compile-time.
For instance, you can do this
However, you cannot do that:
binary_to_list(term_to_binary(#foo.)) ++ atom_to_list(Field))), M).
* 1: syntax error before: ')'
(#foo. throws the syntax error, so does #foo).
Isn't it a drawback? Is it even good Erlang practice?
I don't want to troll. Is there an EEP about setting record names dynamically?
More information about the erlang-questions