[erlang-questions] record type as variable

Brady McCary brady.mccary@REDACTED
Wed Aug 4 19:31:53 CEST 2010


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 <noel@REDACTED> 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:erlang-questions-unsubscribe@REDACTED
>
>


More information about the erlang-questions mailing list