[erlang-questions] Fwd: dict:from_list/1 fragility

Vlad Dumitrescu <>
Mon Dec 17 22:49:02 CET 2007

forgot to post the answer to the list...

---------- Forwarded message ----------
From: Vlad Dumitrescu <>
Date: Dec 17, 2007 9:48 PM
Subject: Re: [erlang-questions] dict:from_list/1 fragility
To: Matej Kosik <>


On Dec 17, 2007 9:11 PM, Matej Kosik <> wrote:
> I think there are two problems with the
>         dict:from_list/1
> function.
> First: it is not trottel-fest (robust against my stupitidity). It lets me call it as follows:
>         E = dict:from_list([{a,b},{c,d}]).
> Instead of any kind of complain, it vigorously continues and binds E to an invalid dictionary. At
> the first sight, things seem to be fine. This
>         dict:fetch(a, E).
> yields
>         b
> and this
>         dict:fetch(c, E).
> yields
>         d

Exactly as expected and documented. Why do you think it should be
invalid? The dict contains {Key, Value} tuples, and the Value can be
any term.

> Hitherto everything seems fine. However, after I update the dictionary:
>         F = dict:update(e, f, E).

What version of Erlang are you using? The documentation for dict:update/3 states

update(Key, Fun, Dict1) -> Dict2


Key = term()
Fun = fun(Value1) -> Value2   <----- this isn't an atom, but a fun!
 Value1 = Value2 = term()
Dict1 = Dict2 = dictionary()

and calling it in recent versions (R10 and later) gives

=ERROR REPORT==== 17-Dec-2007::21:45:53 ===
Error in process <0.30.0> with exit value: {function_clause,[{dict,update_bkt,[e

** exited: {function_clause,[{dict,update_bkt,[e,f,[]]},
                             {shell,eval_loop,3}]} **

So maybe you are doing something wrong?

best regards,

More information about the erlang-questions mailing list