Can I use a record as a recording element

I want to define a larger record using a composition of smaller records to make the ad more readable.

I am 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 any way to do this?

+3
source share
2 answers

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

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

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

Thanks...

+5
source

Yes there is - wxErlang uses this a lot for event reporting. Usage syntax looks like

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

where the eventexternal record field is set to empty wxCommand.

Matching Ad

%% @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 
0
source

Source: https://habr.com/ru/post/1715706/


All Articles