是否可以将记录用作记录元素

时间:2009-08-21 11:57:47

标签: erlang

我想使用较小记录的复合来定义大型记录,以使声明更具可读性。

我正在尝试做这样的事情:

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

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

以上当然不编译: - (

有没有办法做到这一点??

2 个答案:

答案 0 :(得分:5)

最后在教程中找到答案.....

-record(name,{first =“Robert”,last =“Ericsson”})。

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

谢谢...

答案 1 :(得分:0)

是的,有 - wxErlang对事件消息使用了很多。使用语法类似于

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

其中外部记录的event字段设置为空wxCommand

相应的声明是

%% @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 
相关问题