理解dict的返回类型:在erlang中获取

Ped*_*rez 1 erlang

我使用两种不同的方式创建一个字典,然后我得到结果,但我有两个不同的结果.
我想了解原因.

使用dict:追加

Dict1 = dict:append(key, value, dict:new()).
dict:fetch(key, Dict1).
% I get a list with the value
[value] 
Run Code Online (Sandbox Code Playgroud)

使用dict:from_list

Dict2 = dict:from_list([{ key, value }]).
dict:fetch(key, Dict2).
% I get the value
value
Run Code Online (Sandbox Code Playgroud)

为什么返回类型不同?
获取文档

Dog*_*ert 6

dict:append/3的文件说:

将新值附加到与Key关联的当前值列表.

它的意思是在dict的值总是列表时使用.你可以看到,Dict1是从字典key[value]Dict2是从字典keyvalue:

> dict:to_list(Dict1).
[{key,[value]}]
> dict:to_list(Dict2).
[{key,value}]
Run Code Online (Sandbox Code Playgroud)

如果要按原样存储值而不是列表,可以使用dict:store/3:

> Dict3 = dict:store(key, value, dict:new()).
{dict,1,16,16,8,80,48,
      {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
      {{[],[],[],[],[],[],[],[],[],
        [[key|value]],
        [],[],[],[],[],[]}}}
> dict:fetch(key, Dict3).
value
Run Code Online (Sandbox Code Playgroud)