为什么没有> 0在Erlang? [英] Why is nil > 0 true in Erlang?
本文介绍了为什么没有> 0在Erlang?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这个决定背后的故事是什么?
其他语言似乎有所不同。
Python:
code>无> 0
#False
JavaScript:
null> 0
// false
Ruby:
nil> 0
NoMethodError:未定义的方法`>'为nil:NilClass
解决方案
在Erlang中,任何术语都可以与任何其他术语进行比较。
Erlang Term Comparisons的订单是:
number<原子参考<乐趣端口pid <元组地图无列表<位串
因此 nil> 0 是 true 有关术语比较的更多信息
Erlang is the first language I come across to give true for nil > 0.
What is the story behind this decision?
Other languages seem to behave differently.
Python:
None > 0
# False
JavaScript:
null > 0
// false
Ruby:
nil > 0
NoMethodError: undefined method `>' for nil:NilClass
解决方案
In Erlang, Any term may be compared with any other term. The ordering for Erlang Term Comparisons is:
number < atom < reference < fun < port < pid < tuple < map < nil < list < bit string
thus nil > 0 is true more information on Term Comparisons
这篇关于为什么没有> 0在Erlang?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文