Alternatives to records

Peter Andersson Peter.Andersson@REDACTED
Wed Dec 6 16:18:26 CET 2000


Hi,

I'm looking for a data representation to use as an alternative to Erlang records
in a particular application of mine. I want the possibility to reference data
elements by means of labels rather than positions.  

The reason for not using records in the first place is that, in this case, I
want the possibility to retrieve the data dynamically, like "get_value(Key,
Record)", which is impossible with records (since the names must be hardcoded).
I would prefer to handle the data in a "side-effect-free" fashion, i.e. not use
explicit tables for storage, but pass the values around as arguments. The
structures will never contain many or large elements but there will be *many* of
the structures being created on multiple processes during the lifetime of the
application and they will be accessed frequently. Insert/lookup must be
efficient!

I'm thinking a simple list of key-value tuples ([{key1,Val1},...]) would be the
best choice, since the lists should never be really big (the simplest anyway,
with already existing support by the lists:key* functions). I thought I'd post
this question to the list, though. (I'm often surprised how much there is to
learn from the discussions here - the detailed ones as well as the more general
ones!). Are there any other alternative representations worth considering? Or
are there perhaps ways to reference Erlang record elements dynamically that I
haven't thought of or found out about (not using the tuple representation, that
is)?

Regards

  /Peter



More information about the erlang-questions mailing list