[erlang-questions] Accessing default values of a record

Sean Hinde <>
Tue Jan 9 13:24:20 CET 2007


I'm looking (staring actually!) at a generic function for doing  
mnesia table transformations (e.g. at startup after a code upgrade).

It is easy enough to programmatically work out the difference between  
new and old record fields by comparing the existing mnesia:table_info 
(Tab, attributes) with the record_info in the new code.

But there seems to be no obvious way to access default values in the  
new record definition. This would be useful to give new fields in the  
transformed tables nice default values.

One way to achieve this would be to provide a mechanism akin to  
record_info, but which constructs a default record from its name e.g.

-record(test, {key, val, new_val = []}).

mk_rec(Rec_name) ->
     record_info(default, Rec_name).

1> test:mk_rec(test).
{test, undefined, undefined, []}

Seem like a useful idea?


More information about the erlang-questions mailing list