[erlang-questions] Dynamically access record fields

Jeremy Ong jeremy@REDACTED
Sat Feb 9 22:40:29 CET 2013


Hmm, upon reading more, it seems like all record functionality is
implemented in the compiler pass.

It seems like the ability to address particular variable named locations in
tuples would be desirable. I guess I'll have to use proplists or a dict for
now, although it feels like overkill for what I'm doing.


On Sat, Feb 9, 2013 at 1:37 PM, Jeremy Ong <jeremy@REDACTED> wrote:

> 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/05e54603/attachment.htm>


More information about the erlang-questions mailing list