[erlang-questions] the semantics of dict:append/3

Ulf Wiger (TN/EAB) ulf.wiger@REDACTED
Sun Sep 17 13:48:15 CEST 2006


During a recent QuickCheck course, one of our guys (Johan Tjäder) started playing with applying QuickCheck to the dict.erl module. The following behaviour came as a surprise:

1> D0 = dict:new().
{dict,0,
      16,
      16,
      8,
      80,
      48,
      {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
      {{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]}}}
2> D1 = dict:append(a, 1, D0).
{dict,1,
      16,
      16,
      8,
      80,
      48,
      {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
      {{[],[[a,1]],[],[],[],[],[],[],[],[],[],[],[],[],[],[]}}}
3> dict:find(a,D1).
{ok,[1]}


The documentation has this to say about dict:append/3:

  "This function appends a new Value to the current list
   of values associated with Key. An exception is generated
   if the initial value associated with Key is not a list
   of values."

(http://www.erlang.org/doc/doc-5.5.1/lib/stdlib-1.14.1/doc/html/dict.html#append/3)

I would have thought that the initial value associated
with a key not present in the dictionary is undefined -
not the empty list. Shouldn't then the above experiment
result in a badarg?

BR,
Ulf Wiger




More information about the erlang-questions mailing list