record _info and guard record(X) seems to refuse variable as argument.

Ingela Anderton <>
Tue Aug 8 12:50:32 CEST 2000


 wrote:
> sorry , previsou posting was unclear.
> 
> i mean, record_info refuse variable as table name.
Well, that is because all records are handled by the precompiler and
all reference to records are translated into tuples and tuple functions.
I had a similar problem where I wanted to be able to be able to
traverse a set of records creating lists with the record fields that
where not undefined. I solved the problem with help of the following
structure where I automatically generated the select function with an
appropriate fun.  

-record(header, {title, 
		 bold,  % true | false 
		 title_align, 
		 title_valign	 
		}).
...


fields(header) ->
    record_info(fields, header);
...

select(Record, header, title) ->
    Record#header.title;
select(Record, header, bold) ->
    Record#header.bold;
select(Record, header, title_align) ->
    Record#header.title_align;
select(Record, header, title_valign) ->
    Record#header.title_valign;
....



-- 
/m.v.h Ingela

//The highway of life is always under construction. //

 	        |\      _,,,--,,_  ,)
                /,`.-'`'   -,  ;-;;' 
               |,4-  ) )-,_ ) /\
              '---''(_/--' (_/-'

Ericsson Utvecklings AB             Phone :   +46 8 719 18 13
Open Systems (f.d. Erlang Systems)  Cellular/Mobile: +46 70 636 78 68 
Torshamnsgatan 39 B
Box 1214                            http://www.erlang.se
S-164 28 KISTA, SWEDEN              





More information about the erlang-questions mailing list