[erlang-questions] Field name to tuple element number at compile time

Joel Reymont joelr1@REDACTED
Wed Aug 27 17:16:40 CEST 2008


#foo.bar, or generally #rec_name.field does it.

This is perfectly valid:

-module(x).

-compile([export_all]).

-record(foo, {bar, baz}).

t() ->
	#foo.bar.

On Aug 27, 2008, at 4:01 PM, Joel Reymont wrote:

> Suppose I have -record(foo, { bar, baz }). I understand that I can  
> do record_info(fields, foo) and get a list of fields at compile time.
>
> Is there a way to translate bar into 2 at compile time as well?

--
wagerlabs.com








More information about the erlang-questions mailing list