04 Comparison Functions

The comparisons/ library provides additional equality and ordering operations.

4.1. Comparison functions

4.1.1. comparisons/not=

Function

(comparisons/not= value more*) → boolean

Returns the negation of the corresponding equality call. This means that not all arguments are equal, rather than requiring every pair to differ. One argument returns false; no arguments is an error. Equality retains its matching-kind checks and stops comparing after the first unequal pair.

DUST
(comparisons/not= 1 2)
(comparisons/not= 1 1)
(comparisons/not= 1)
(comparisons/not= 1 2 "x")
=
DUST Result
true
false
false
true
DUST
(comparisons/not= 1 1.0)
=
DUST Result
#err <mismatch type>
DUST
(comparisons/not=)
=
DUST Result
#err <argument missing>

4.1.2. !=

Function

(!= value more*) → boolean

Is another name for comparisons/not=. It takes the same arguments and returns the same results and errors.

4.1.3. comparisons/identical?

Function

(comparisons/identical? a b) → boolean

Returns true if its operands refer to the same value, otherwise false. Errors raised at the same place with the same tags and message may be the same value.

DUST
(comparisons/identical? 1 1.0)
=
DUST
(comparisons/identical? "hello" "hello")
=
DUST
(comparisons/identical? [1 2] [1 2])
=
DUST
(comparisons/identical? {x 1} {x 1})
=
DUST
(comparisons/identical? `[] [])
=
DUST
(comparisons/identical? `[1 2] [1 2])
=
DUST
(let [es (map (fn [i] (/ i 0)) [1 2])] (comparisons/identical? (first es) (lists/second es)))
(let [es (map (fn [s] (int s)) ["x" "y"])] (comparisons/identical? (first es) (lists/second es)))
(let [es (map (fn [v] (/ 1 v)) [0 "a"])] (comparisons/identical? (first es) (lists/second es)))
(comparisons/identical? (/ 1 0) (/ 2 0))
(let [es (map (fn [i] (/ i 0)) [1 2])] (= (first es) (lists/second es)))
(map (fn [i] (/ i 0)) [1 2])
=
DUST Result
#err {<division integer zero>
      message "division by zero"}
#err {<invalid value>
      message "expected a decimal number string"}
#err {<division integer zero>
      message "division by zero"}
#err {<division integer zero>
      message "division by zero"}
#err {<division integer zero>
      message "division by zero"}
[#err {<division integer zero>
       message "division by zero"}
 #err {<division integer zero>
       message "division by zero"}]
DUST
(let [a {x 1}
      b {x 1}
      c a]
  (comparisons/identical? a b))
→
Canonical DUST
(let [a {x 1} b {x 1} c a] (comparisons/identical? a b))
=
DUST
(let [a {x 1}
      b {x 1}
      c a]
  (comparisons/identical? a c))
→
Canonical DUST
(let [a {x 1} b {x 1} c a] (comparisons/identical? a c))
=
DUST
(let [f (fn [x] x)
      g f
      h (fn [x] x)]
  (comparisons/identical? f g))
→
Canonical DUST
(let [f (fn [x] x) g f h (fn [x] x)] (comparisons/identical? f g))
=
DUST
(let [f (fn [x] x)
      g f
      h (fn [x] x)]
  (comparisons/identical? f h))
→
Canonical DUST
(let [f (fn [x] x) g f h (fn [x] x)] (comparisons/identical? f h))
=