2010-12-02 57 views
2

我有一本字典,我用它来存储使用参数名称的另一个字典。在爱尔兰的字典中存储字典

我得到一个右侧不匹配错误。

这里是我的代码

handle_cast({setState, Id}, State) -> 
Id0 = dict:new(), 
DQueue = queue:new(), 
UQueue = queue:new(), 
Id1 = dict:store(dQueue, [DQueue], Id0), 
Id2 = dict:store(uQueue, [UQueue], Id1), 
Id3 = dict:store(dSpeed, [], Id2), 
Id4 = dict:store(uSpeed, [], Id3), 
D = dict:store(Id, [Id4], State), 
State = D, 
{noreply, State}; 

林不知道哪里错误的来源。我认为这可能是因为我将Id作为主字典中的关键字,并以新的内部字典作为值。

我需要内部字典的名称作为Id的值,因为它们中会有很多,我需要稍后通过Id访问它们。

我是否正确设置字典? erlang是否允许字典持有字典?

感谢

回答

5

没有尝试的代码,我敢打赌,你badmatch鉴于State是在函数的头部已经被绑定在做State = D时。除此之外,USpeedDSpeed应该是未定义的,除非您复制/粘贴您的功能错误。

+0

谢谢。我改变了一些东西。它是uni项目的一部分:P我现在将编辑这些感谢。所以我应该让它例如NewState = D. {noreply,NewState}。 ? ;) – jarryd 2010-12-02 23:11:46

+0

要么或只是`{noreply,D}` – 2010-12-02 23:31:34

3

如何重写:

handle_cast({setState, Id}, State) -> 
    D = dict:from_list([{dQueue, [queue:new()]}, 
         {uQueue, [queue:new()]}, 
         {dSpeed, []}, 
         {uSpeed, []}], 
    {noreply, D}; 

这是简单的阅读,避免了命名的麻烦和大约相同的速度。