Mnesia: Tables on the fly.

Chris Pressey <>
Wed Jul 3 08:47:27 CEST 2002


On Tue, 02 Jul 2002 18:57:41 -0500
"martin logan" <> wrote:

> Hello All, I seem to be facing a small problem having to do with mnesia.
> I have the following code:
> 
> % definitions of all the tables we are going to create
>     MappingTabDef = [{type, set}, {ram_copies, [node()]}, {attributes, 
> record_info(fields, mapping)}],
> % More tables here.
> 
> % create the tables
> mnesia:create_table(mapping, MappingTabDef),
> % Create more tables here
> 
> 
> I would like to replace that with somthing like the following:
> Tables = [{mapping, ram_copies}|T],
> 
> Fun = fun({Table, StoreType}) ->            create_table([{type, set}, 
> {StoreType, [node()]}, {attributes, record_info(fields, Table)}] end,
> 
> lists:foreach(Fun, Tables),
> 
> When I statically define everything as illustrated in the first example 
> things work perfectly. Unfortunatly the second bit of code blows up
> every time.  Does anyone understand why?

record_info only works at compile-time.  (The record name must be a
literal constant).

-Chris



More information about the erlang-questions mailing list