Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is nil > 0 true in Erlang?

Tags:

erlang

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
like image 609
Dimitris Zorbas Avatar asked Jan 11 '17 19:01

Dimitris Zorbas


1 Answers

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

like image 173
byaruhaf Avatar answered Sep 21 '22 05:09

byaruhaf