[erlang-questions] Generating a variable in a macro

Mats Cronqvist mats.cronqvist@REDACTED
Tue Jan 9 16:03:58 CET 2007


Joel Reymont wrote:
> I thought of that but there's record_info which is compile-time.
> 
> On Jan 9, 2007, at 11:50 AM, Mats Cronqvist wrote:
> 
>> Joel Reymont wrote:
>>> Any workarounds apart from passing the  error variable as a macro 
>>> argument?
>>
>>   turn make_shared_table/3 into a function?
>>

   i thought i was missing something...

   how about this;

   -define(ri(Rec),{Rec,record_info(fields,Rec)}).

used like this;

     make_shared_table(?ri(counter)).

   e.g.
-record(counter,{joel,rules}).
-define(ri(Rec),{Rec,record_info(fields,Rec)}).
x()-> (?ri(counter)).

   calling x/0 will return {counter,[joel,rules]}

   mats



More information about the erlang-questions mailing list