【原创】Erlang 之 match 和 compare equal

简介:

     在学习 Erlang 过程中,经常会遇到以下两个和比较相关的操作:match 和 compare equal 。现作如下解释:
     当两个 Erlang term 拥有完全相同类型和值时,我们称它们 match 。例如:1 match 1 为 true ,但 1 match 1.0 为 false 。
     当两个 Erlang term 拥有完全相同类型和值时,或者两者均为数值类型,且可以延伸为相同的值时,我们称它们 compare equal 。例如,1 compare equal 1 为 true,且 1 compare equal 1.0 为 true 。

另外一个比较直观的说法是:

The difference being the same as between =:= and ==.
即 match 相当于 =:= ,而  compare equal 相当于 == 。
     在实际应用中,ETS 中 set 类型的表采用的是 match ,而 ordered_set 类型的表采用的是 compare equal
原文参考:
Also worth noting is the subtle difference between matching and comparing equal, which is demonstrated by the different table types set and ordered_set. Two Erlang terms match if they are of the same type and have the same value, so that 1 matches 1, but not 1.0 (as 1.0 is a float() and not an integer()). Two Erlang terms compare equal if they either are of the same type and value, or if both are numeric types and extend to the same value, so that 1 compares equal to both 1 and 1.0. The ordered_set works on the Erlang term order and there is no defined order between an integer() and a float() that extends to the same value, hence the key 1 and the key 1.0 are regarded as equal in an ordered_set table.


目录
相关文章
|
11月前
|
Python
33.从入门到精通:Python3 正则表达式 re.match函数 re.search方法 re.match与re.search的区别
33.从入门到精通:Python3 正则表达式 re.match函数 re.search方法 re.match与re.search的区别
ES中 minimum_should_match 的用法和误区
ES中 minimum_should_match 的用法和误区
ES中 minimum_should_match 的用法和误区
PAT (Advanced Level) Practice - 1053 Path of Equal Weight(30 分)
PAT (Advanced Level) Practice - 1053 Path of Equal Weight(30 分)
101 0
PAT (Advanced Level) Practice - 1060 Are They Equal(25 分)
PAT (Advanced Level) Practice - 1060 Are They Equal(25 分)
82 0
|
C语言
全网首发:Undefined symbols for architecture x86_64: “std::__1::locale::use_facet(std::__1::locale::id&)
全网首发:Undefined symbols for architecture x86_64: “std::__1::locale::use_facet(std::__1::locale::id&)
233 0
|
IDE 开发工具 Python
原创| Python中"等于"到底用 == 还是 is ?
原创| Python中"等于"到底用 == 还是 is ?
232 0
原创| Python中"等于"到底用 == 还是 is ?
|
Python
说说Python中search()和match()的区别?
公众号新增加了一个栏目,就是每天给大家解答一道Python常见的面试题,反正每天不贪多,一天一题,正好合适,只希望这个面试栏目,给那些正在准备面试的同学,提供一点点帮助!
94 0
成功解决Python中出现的ValueError: not enough values to unpack (expected 2, got 1)的问题
成功解决Python中出现的ValueError: not enough values to unpack (expected 2, got 1)的问题
成功解决Python中出现的ValueError: not enough values to unpack (expected 2, got 1)的问题