WhizzML Reference Manual

4.2 Equality

(= obj1 …) \(\rightarrow \) boolean
(!= obj1 …) \(\rightarrow \) boolean

Values of any type can be compared for (structural) equality using the = procedure which takes one or more arguments and evaluates to true only if all the values are equal. For example:

(= 1)  ;; => true
(= 1 "one") ;; => false
(let (x "one") (= x "one"))  ;; => true
(= {"a" 3 "b" "hello"}
   {"b" "hello" "a" (+ 1 2)}
   {"a" 3 "b" (str "he" "llo")})  ;; => true

The operator != is the logical complement to =.

(!= "hi") ;; => false
(!= "hi" "hi")   ;; => false
(!= "Hi" "hi")    ;; => true
(!= 1 (- 2 1) 3)  ;; => true

The resources and objects created in WhizzML can be compared using the compare-objects procedure.

(compare-objects res res) \(\rightarrow \) list

The result of the call is a list of the attributes that differ. For identical objects, the result is an empty list, e.g.:

(compare-objects {"first-key" "string"
                  "second-key" 2
                  "third-key" [1 2]}
                 {"first-key" "string"
                  "second-key" 2
                  "third-key" [1 2]})
;; => []

If the objects are different, the list has an element for each different attribute. It describes the path to the attribute in the map structure, the value of the attribute in each object, the type of difference and a message describing it. The type of differences range from different value types, different lengths for lists, different values or missing keys.

(compare-objects {"first-key" "string"
                  "second-key" 2
                  "third-key" [1 2]}
                 {"first-key" "a different string"
                  "second-key" 3
                  "third-key" [1 4]
                  "fourth-key" "new attribute"})
;; => [{"path1" ["first-key"]
;;      "path2" ["first-key"]
;;      "obj1" "string"
;;      "obj2" "a different string"
;;      "type" "eq"
;;      "msg" "The strings in [first-key] differ."}
;;     {"path1" ["second-key"]
;;      "path2" ["second-key"]
;;      "obj1" 2
;;      "obj2" 3
;;      "type" "eq"
;;      "msg" "The numbers in [second-key] differ."}
;;     {"path1" ["third-key" 1]
;;      "path2" ["third-key" 1]
;;      "obj1" 2
;;      "obj2" 4
;;      "type" "eq"
;;      "msg" "The numbers in [third-key 1] differ."}
;;     {"path1" []
;;      "path2" ["fourth-key"]
;;      "obj1" ""
;;      "obj2" "new attribute"
;;      "type" "missing"
;;      "msg" "The key fourth-key is missing in the left hand side."}]