[erlang-questions] record type as variable

Brady McCary <>
Wed Aug 4 19:31:53 CEST 2010


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.


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