Converting list of tagged tuples to a record

Silas Silva silasdb@REDACTED
Thu Sep 2 08:23:52 CEST 2010

Hello all,

In my newbie application, I receive a bunch of data from HTTP's POST
(I'm using Mochiweb), in the following format (supposing a person's

    [{first_name, value}, {last_name, value}, ...]

And I have the definition of the record for the person:

    -record(person, {first_name, last_name, ...}).

alistair in the #erlang channel in freenode, gave me a nice solution to
put this list in the record:

    lists:foldl(fun add_to_record/2, #person{}, List).

    add_to_record({first_name, value}, rec) ->
        rec#person{first_name = value};

    add_to_record({last_name, value}, rec) ->
        rec#person{last_name = value};


That works.  My questions are:

1. Are there other [good practice] ways to transform information coming
   from a UI (which, must of the times, come as a list) in well
   specified records?

2. Is it common to use records of records?  Is it possible?  For example:

    -record(name, {last_name, first_name}).
    -record(person, name, ...)


Silas Silva

More information about the erlang-questions mailing list