record field names
Mats Cronqvist
mats.cronqvist@REDACTED
Fri Sep 16 17:04:37 CEST 2005
name clashes? surely you can't have a real record_info/2 function?
mats
Ulf Wiger (AL/EAB) wrote:
> In order to eliminate name clashes, why not
>
> Module:module_info({record, Rec, fields})
>
> /Uffe
>
>
>>-----Original Message-----
>>From: owner-erlang-questions@REDACTED
>>[mailto:owner-erlang-questions@REDACTED]On Behalf Of Mats Cronqvist
>>Sent: den 16 september 2005 16:22
>>To: erlang-questions@REDACTED
>>Subject: record field names
>>
>>
>> feels like this is an faq, but i can't find it in the archive.
>>
>> according to the reference manual:
>> "To each module using records, a pseudo function is added
>>during compilation
>>to obtain information about records:
>>record_info(fields, Record) -> [Field]
>>record_info(size, Record) -> Size"
>>
>> now, as i understand it, there is no function, just
>>textual substitution
>>(like a macro).
>>
>> but why not? if there was a real, exported function
>>record_info/2 (just like
>>module_info), one could do a lot of cool things.
>>
>> such as turning a record into a tagged tuple;
>>
>>readable_rec(Module,Rec) ->
>>
>>lists:zip(Module:record_info(fields,element(1,Rec)),tl(tuple_t
>>o_list(Rec))).
>>
>> or write a tool to check that all modules using a certain
>>record agree on its
>>definition.
>>
>> mats
>>
More information about the erlang-questions
mailing list