[erlang-questions] Noob alert: tuple to record?
Torben Hoffmann
torben.lehoff@REDACTED
Thu Dec 4 23:19:39 CET 2008
Hi Peter,
This is a painful area.
Sadly, you cannot do this automatically. You can do various tricks with the
internal representation of the records - see
http://www.erlang.org/doc/reference_manual/records.html#8.7 - but it will
never be beautiful.
A possible solution:
use Fields=record_info(fields,<your record name>) to get the list of fields
in the record and then for each {Name,Value} pair you find out the position
of the Name in the Fields list and the do a nasty
setelement(Position,Record,Value) to set the value.
Another question before you dive in: you have a nice list of {Name,Value}
which matches with the proplists module, perhaps you do not need to put the
things into a record?
Could you tell us a bit more about what problem you are trying to solve on
the level above your particular question?
Cheers,
Torben
On Thu, Dec 4, 2008 at 9:34 PM, Peter Sabaini <peter@REDACTED> wrote:
> Hello list,
>
> Please forgive the noobness: if I have a list of {Name, Value} pairs
> corresponding to names defined in a record, is there a way to set those
> values
> in a record automatically?
>
> Thanks,
> peter.
> --
> Peter Sabaini
> http://sabaini.at/
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20081204/8339d5b3/attachment.htm>
More information about the erlang-questions
mailing list