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

Vlad Dumitrescu vladdu55@REDACTED
Mon Dec 17 22:49:02 CET 2007


forgot to post the answer to the list...


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


Hi!

On Dec 17, 2007 9:11 PM, Matej Kosik <kosik@REDACTED> 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

Types:

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
,f,[]]},{dict,on_bucket,3},{dict,update,3},{erl_eval,do_apply,5},{erl_eval,expr,
5},{shell,exprs,6},{shell,eval_loop,3}]}

** exited: {function_clause,[{dict,update_bkt,[e,f,[]]},
                             {dict,on_bucket,3},
                             {dict,update,3},
                             {erl_eval,do_apply,5},
                             {erl_eval,expr,5},
                             {shell,exprs,6},
                             {shell,eval_loop,3}]} **

So maybe you are doing something wrong?

best regards,
Vlad



More information about the erlang-questions mailing list