zl程序教程

您现在的位置是:首页 >  其它

当前栏目

【原创】Erlang 之 match 和 compare equal

原创 match erlang Compare equal
2023-09-14 08:59:45 时间

     在学习 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.


LeetCode第三题(Longest Substring Without Repeating Characters)三部曲之三:两次优化 本文是《LeetCode第三题(Longest Substring Without Repeating Characters)三部曲》的第二篇,前一篇文章已经列出了完整的解题思路,今天来将此思路转化为具体的Java代码