在 Erlang shell 中:
> orddict:fetch(b, [{d, 2}, {a, 1}, {b,5}, {c,9}]).
** exception error: no function clause matching
orddict:fetch(b,[{d,2},{a,1},{b,5},{c,9}])
但
> orddict:fetch(b, [{a, 1}, {b,5}, {c,9}]).
5
我在这里缺少什么?
引用文献:orddict:fetch/2
The orddict docs将命令描述为
orddict() = [{Key :: term(), Value :: term()}]
.
最佳答案
解决这个问题的关键在the docs :
The list is ordered after the keys.
使用 orddict:from_list/1从
{key, value}
的常规列表转换对。> orddict:fetch(b, orddict:from_list([{d, 2}, {a, 1}, {b,5}, {c,9}])).
5
关于erlang - 为什么是 orddict :fetch/2 being crazy?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8216873/