Unfortunately, record_info is not really a function, even if it looks like one.
You can verify this by testing the following. Create a file:
-module(something). -record(a, {}).
Launch the Erlang shell:
> rr(something). [a] > record_info(fields, a). [] > A = a. > record_info(fields, A). * 2: illegal record info
So my recommendation would be to use a macro or a specialized function for the record_info part.
To answer your initial question. Use something like:
tables() -> [?TABLE_MACRO(tablename), ?TABLE_MACRO(tablename2), ...].
where TABLE_MACRO looks something like this:
-define(TABLE_MACRO(Table), fun() -> mnesia:create_table(Table, [{disc_copies, Nodes}, {attributes, record_info(fields, Table)}]) end).
and then a function using something like below.
[case CreateTable of {aborted, {already_exists, _}} -> ok; {atomic, ok} -> ok end || CreateTable <- tables()].
Ugh! You can clean it up a bit, but I hope you understand the general idea.
- Macro instead of using a variable.
- Matches both {atomic, ok} and {aborted, {already_exists, _TableName}}