Key = 2/2,
FindReuslt = lists:keyfind(Key, 1, [{1, 1}],
case FindReuslt of
{Key, Value} ->
find;
false ->
not_find
end.
这段代码会报没有匹配的错误
原因是 Key = 2/2 其实 Key被赋值为1.0 (摔,这个基础概念都能忘记)
这里回到基础概念
erlang 中
== 是equal 1.0 == 1 true
=:= 是 exactly equal 1.0 =:= 1 false
所以lists:keyfind时会查找到结果,但是在匹配时就找不到对应项。