is_equal


is_equal(obj1, obj2)
      

Return true if obj1 and obj2 have the same structure and contents, otherwise return false.

Two objects are equal if each of their constituent parts are equal according to is_eqv.

The equals operator (==) have the same behavior as is_equal and the not-equals operator (<>) have the same behavior as not(is_equal(a, b)).

Is_equal is a generic function by default and can be overridden for custom datatypes without an explicit declare generic.

Examples:


is_equal([1, 2, [3, 4]], [1, 2, [3, 4]])
// true

[1, 2, [3, 4]] == [1, 2, [3, 4]]
// true
    
is_equal("hello", "hello")
// true

is_equal("hello", "hEllo")
// false

not(is_equal("hello", "hEllo"))
// true

"hello" <> "hEllo"
// true
      

The operators == and <> will recognize custom types, if they respond to the 'is_equal message. This is demonstrated by the next program.


function point(x, y)
  ^(message)
  | 'get -> [x, y]
  | 'is_equal -> ^(p) p.get == [x, y]
  
let p1 = point(10, 20)
let p2 = point(10, 20)
let p3 = point(10, 30)
p1 == p2
// true
p1 == p3
// false
p1 <> p3
// true
      

Is_equal cannot be used to compare two function objects. Always use is_eq for this.


let f = sqrt
is_eq(f, sqrt)
// true
is_eq(f, sin)
// false
      

Also see:

is_eqv
is_eq
compare
string_is_eq
number_is_eq


Core Module Index | Contents