tags:

views:

68

answers:

2

I want to define a large record using a composite of smaller records, in an attempt to make the declaration more readable.

I'm trying to do something like this:

-record(molly, {xx=0, yy=1}).

-record(harry, {#molly, zz=2}.

The above of course does not compile :-(

Is there some way to do this ??

A: 

Yes, there is -- wxErlang uses this a lot for event messages. The use syntax looks like

#wx{id=1, event=#wxCommand{}}

where the event field of the outer record is set to an empty wxCommand.

The corresponding declaration is

%% @type wx() = #wx{id=integer(), obj=wx:wxObject(), userData=term(), event=Rec}. Rec is a event record.
-record(wx, {id,     %% Integer Identity of object.
             obj,    %% Object reference that was used in the connect call.
             userData, %% User data specified in the connect call.
             event}).%% The event record
Steve Gilham
Yes, I see, but that's at initialise time, I'm trying to do this at definition time in header file.
+5  A: 

Finally found the answer in a tutorial.....

-record(name, {first = "Robert", last = "Ericsson"}).

-record(person, {name = #name{}, phone}).

Thanks ...