[erlang-questions] record type as variable

Noel Bush <>
Wed Aug 4 22:27:18 CEST 2010


Tino Breddin pointed me to parse_trans, which creates record access
functions and looks like it will be very useful for me.

I know that the record syntax is syntactic sugar, so I guess my
imaginary example was formed incorrectly. But it looks like
parse_trans will let me do stuff like '#new-'(r) to make a new record
of type r, and so forth. Pretty cool.

parse_trans is here: http://github.com/esl/parse_trans

Noel

On Wed, Aug 4, 2010 at 7:31 PM, Brady McCary <> wrote:
> Noel,
>
> The record syntax is syntactic sugar on top of the tuple syntax. When
> erlang source is read, the record syntax is mechanically transformed
> into a tuple. Because records are implemented in this way at compile
> time, there is no way for the compiler to know the value of Type.
>
> So the answer is no.
>
> Brady
>
> On Wed, Aug 4, 2010 at 12:05 PM, Noel Bush <> wrote:
>> Is there any way to specify the type of a record using a variable? I
>> want to be able to do this sort of thing:
>>
>> create(Type, Name) ->
>>    #Type{name = Name}.
>>
>> (Obviously, I'm responsible for making sure that Type corresponds to a
>> record type, that any record type has a name field, etc.) It doesn't
>> seem like that much of a pain to write a few record-handling functions
>> that would allow me to do this, but it would be great to find out that
>> someone's already done the work.
>>
>> Thanks,
>> Noel
>>
>> ________________________________________________________________
>> erlang-questions (at) erlang.org mailing list.
>> See http://www.erlang.org/faq.html
>> To unsubscribe; mailto:
>>
>>
>


More information about the erlang-questions mailing list