erlang - 为什么是 orddict :fetch/2 being crazy?

标签 erlang

在 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/

相关文章:

erlang - 是否可以将本地事件处理程序添加到远程事件管理器

erlang - 通过以编程方式指定要修改的字段来修改 Erlang 中的记录

erlang - 如何发出 Riak 搜索查询?

ssl - 更新 Erlang 后从 SSL 混合 local.hex 失败

erlang - 测试字符串是否是数字

erlang - 如何细化调试?

erlang - 等于和完全等于项比较运算符之间的差异

linux - Tsung : config error, 正在中止

列出 :append with list comprehensions

process - 为什么erlang中使用 'monitor'选项:spawn_opt disabled?