[erlang-questions] Fold on empty dict

Alexey Romanov alexey.v.romanov@REDACTED
Thu Dec 30 13:00:34 CET 2010


The problem isn't that the function should do something meaningful,
but it should have 3 arguments (Key, Value, AccIn):

1> dict:fold(fun(E1, E2, E3) -> E1 end, [], dict:new()).
[]

Yours, Alexey Romanov



On Thu, Dec 30, 2010 at 2:54 PM, Alessandro Sivieri
<alessandro.sivieri@REDACTED> wrote:
> Hi all,
>
> I have just found out that dict:fold() explodes on an empty dict:
>
> Erlang R14B01 (erts-5.8.2) [source] [64-bit] [smp:2:2] [rq:2]
> [async-threads:0] [kernel-poll:false]
>
> Eshell V5.8.2  (abort with ^G)
> 1> D = dict:new().
> {dict,0,16,16,8,80,48,
>      {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
>      {{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]}}}
> 2> dict:fold(fun(El) -> El end, [], D).
> ** exception error: no function clause matching
> dict:fold_bucket(#Fun<erl_eval.6.13229925>,[],[])
>     in function  dict:fold_seg/4
>     in call from dict:fold_segs/4
>
> Shouldn't this return the empty list? Of course, in a real case the inner
> fun should do something meaningful...
>
> --
> Sivieri Alessandro
> alessandro.sivieri@REDACTED
> http://www.chimera-bellerofonte.eu/
> http://www.poul.org/
>


More information about the erlang-questions mailing list