lib: remove useless usage of `is`
[nit.git] / lib / standard / kernel.nit
index efb6819..bf158a3 100644 (file)
@@ -13,7 +13,7 @@
 
 # Most minimal classes and methods.
 # This module is the root of the standard module hierarchy.
-package kernel
+module kernel
 
 import end # Mark this module is a top level one. (must be only one)
 
@@ -66,6 +66,12 @@ interface Object
 
        # Return the global sys object, the only instance of the `Sys` class.
        protected fun sys: Sys is intern
+
+       # The hash code of the object.
+       # Assuming that a == b -> a.hash == b.hash
+       ##
+       # Without redefinition, it is based on the `object_id` of the instance.
+       fun hash: Int do return object_id / 8
 end
 
 # The main class of the program.
@@ -199,6 +205,14 @@ universal Bool
        redef fun ==(b) is intern
        redef fun !=(b) is intern
        redef fun output is intern
+       redef fun hash
+       do
+               if self then
+                       return 1
+               else
+                       return 0
+               end
+       end
 end
 
 # Native floating point numbers.
@@ -234,6 +248,7 @@ universal Int
        redef type OTHER: Int
 
        redef fun object_id is intern
+       redef fun hash do return self
        redef fun ==(i) is intern
        redef fun !=(i) is intern
        redef fun output is intern
@@ -385,28 +400,6 @@ universal Int
                end
        end
 
-       # Execute 'each' for each integer in [self..last]
-       fun enumerate_to(last: Int)
-               !each(i: Int)
-       do
-               var cur = self
-               while cur <= last do
-                       each(cur)
-                       cur += 1
-               end
-       end
-
-       # Execute 'each' for each integer in [self..after[
-       fun enumerate_before(after: Int)
-               !each(i: Int)
-       do
-               var cur = self
-               while cur < after do
-                       each(cur)
-                       cur += 1
-               end
-       end
-
        # The absolute value of self
        #
        #     assert (-10).abs   == 10
@@ -431,6 +424,7 @@ universal Char
        redef type OTHER: Char
 
        redef fun object_id is intern
+       redef fun hash do return ascii
        redef fun ==(o) is intern
        redef fun !=(o) is intern
        redef fun output is intern
@@ -553,4 +547,6 @@ end
 
 # Pointer classes are used to manipulate extern C structures.
 extern Pointer
+       # Is the address behind this Object at NULL?
+       fun address_is_null: Bool `{ return recv == NULL; `}
 end