[erlang-questions] Generating a variable in a macro

Joel Reymont <>
Tue Jan 9 12:24:07 CET 2007


Folks,

Is there a way to "auto-generate" a variable in a macro ala (gensym)  
in Lisp?

I have a macro that looks like this:

-define(make_shared_table(Table, Nodes, Any),
         case mnesia:create_table(Table,
                                  [
                                   {disc_copies, Nodes},
                                   {type, set},
                                   {attributes, record_info(fields,  
Table)}
                                  ]) of
             {atomic, ok} ->
                 ok;
             Any ->
                 error_logger:error_report([{message, "Cannot install  
table"},
                                            {table, Table},
                                            {error, Any},
                                            {nodes, Nodes}])
         end()).

I use it like this

     ?make_shared_table(counter, Nodes, Any1),
     ?make_shared_table(schema, Nodes, Any2),

Unless I pass Any1, Any2, etc. into the macro, erl will complain that  
the use of Any is unsafe. Any workarounds apart from passing the  
error variable as a macro argument?

	Thanks, Joel

--
http://wagerlabs.com/








More information about the erlang-questions mailing list