[erlang-questions] Dynamically access record fields

Jeremy Ong <>
Sat Feb 9 22:37:42 CET 2013


Suppose I have a record that looks like

-record(foo, {bucket1, bucket2}).

I may want to pass in an argument specifying what bucket to perform the
operation over.

For example,

Bucket = bucket1,

then later,

Use Foo#foo.Bucket for some operations and also modify Bucket with
something like

Foo#foo{Bucket = bar}

Erlang doesn't seem to support this, and I don't see why not? Is there a
better way to go about this?

Real World Example,

If the record stores data about two people playing a game against one
another, and one of them disconnects, I want to perform some operations on
the disconnected player's data, and notify the other player that the
disconnect occurred. Not having this sort of functionality results in some
code duplication and messy code (at least, if using records).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130209/ba6667bb/attachment.html>


More information about the erlang-questions mailing list