core :: Discrete :: defaultinit
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
core :: Comparable :: defaultinit
core :: Discrete :: defaultinit
core :: Object :: defaultinit
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: output_class_name
Display class name on stdout (debug only).
# Discrete total orders.
interface Discrete
super Comparable
redef type OTHER: Discrete
# The next element.
fun successor(i: Int): OTHER is abstract
# The previous element.
fun predecessor(i: Int): OTHER is abstract
# The distance between self and d.
#
# assert 10.distance(15) == 5
# assert 'Z'.distance('A') == 25
fun distance(d: OTHER): Int
do
var cursor: OTHER
var stop: OTHER
if self < d then
cursor = self
stop = d
else if self > d then
cursor = d
stop = self
else
return 0
end
var nb = 0
while cursor < stop do
cursor = cursor.successor(1)
nb += 1
end
return nb
end
end
lib/core/kernel.nit:373,1--410,3