[erlang-questions] the semantics of dict:append/3
Robert Virding
robert.virding@REDACTED
Mon Sep 18 02:54:32 CEST 2006
I would say that seeing there is no value then it cannot be not a list
of values. Ergo it shouldn't generate an error! :-) Orddict behaves the
same way.
I was probably just being nice.
Robert
Ulf Wiger (TN/EAB) wrote:
> 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
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
More information about the erlang-questions
mailing list