[erlang-questions] Dynamically access record fields

Jeremy Ong <>
Sat Feb 9 23:48:58 CET 2013


On Sat, Feb 9, 2013 at 2:25 PM, Ulf Wiger <> wrote:

> Take a look at exprecs.erl in https://github.com/uwiger/parse_trans
>
> https://github.com/uwiger/parse_trans/blob/master/doc/exprecs.md
>
> Thanks I'll take a look.


> BR,
> Ulf W
>
> Ulf Wiger, Feuerlabs, Inc.
> http://www.feuerlabs.com
>
> 9 feb 2013 kl. 22:40 skrev Jeremy Ong <>:
>
> 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 <> 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).
>>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130209/e0515f02/attachment.html>


More information about the erlang-questions mailing list