def eq_default(a, b): # This strongly enforces the null and boolean identity. # You can't mess it up by multimethod introductions. if a == null or b == null: return boolean(a == b) elif isinstance(a, Boolean) or isinstance(b, Boolean): return boolean(a == b) # This reflects how the cmp_ operates, with an exception that # if cmp cannot succeed, we will use the identity equality. args = [a, b] method = cmp_.fetch_method(args, True) if method is None: c = coerce.fetch_method(args, False) if c is not None: args = cast(c.call(args), List, u"coerce should return a list").contents method = cmp_.fetch_method(args, True) if method is not None: return boolean( cast(method.call(args), Integer, u"cmp should return an int").value == 0) else: # This way, the equality and inequality is always defined, # even if comparison is not defined for everything. return boolean(a == b)
def ge_default(a, b): args = [a, b] method = cmp_.fetch_method(args, True) if method is not None: return boolean( cast(method.call(args), Integer, u"cmp should return int").value >= 0) else: args = cast(coerce.call(args), List, u"coerce should return a list") return ge.call_suppressed(args.contents)
def _(a, b): return boolean(a.value == b.value)
def ne_default(a, b): return boolean(is_false(eq.call([a, b])))
def cmp_le(a, b): return boolean(a.number <= b.number)
def cmp_lt(a, b): return boolean(a.number < b.number)
def cmp_le(a, b): return boolean(a.value <= b.value)
def _(a, b): return boolean(a.string == b.string)
def cmp_gt(a, b): return boolean(a.number > b.number)
def cmp_ge(a, b): return boolean(a.value >= b.value)
def cmp_gt(a, b): return boolean(a.value > b.value)
def cmp_lt(a, b): return boolean(a.value < b.value)
def _(a, b): return boolean(a.number == b.value)
def _(a, b): return boolean(a.ref == b.ref)
def cmp_ge(a, b): return boolean(a.number >= b.number)
def ne_default(a, b): return boolean(a != b)
def eq_default(a, b): return boolean(a == b)
def _(a, b): return boolean(a.number == b.number)
def _(a, b): return boolean(a.number != b.number)
def _(a, b): return boolean(a.eq(b))
def _(a, b): return boolean(a.value == b.number)
def cmp_eq(a, b): return boolean(a.eq(b))