chickadee » ck-macros » c-compare?

(c-compare? '(OP ...) X Y) → '#t or '#fsyntax

Recursively compares atoms, pairs, lists, or vectors, using OP as the predicate to compare atoms. Similar to equal? but with a custom predicate. Added in version 0.2.0.

OP will be called with two arguments: an atom of X, and the corresponding atom of Y. In other words, the Nth atom of X will be compared with the Nth atom of Y, descending recursively into nested structures. If X and Y are themselves atoms, they are compared directly with OP.

Yields '#f if X and Y have dissimilar structures (length, nesting, type), or if OP yields '#f for any corresponding atoms of X and Y. Otherwise yields '#t.

(ck () (c-compare? '(c-string-ci=?) '#("a" ("b")) '#("A" ("B"))))
;; ==> #t

;;; X is a vector with a list, but Y is a list with a vector.
;;; The structures are dissimilar.
(ck () (c-compare? '(c-string-ci=?) '#("a" ("b")) '("a" #("b"))))
;; ==> #f

;;; Can use any predicate. Here, X and Y have same structure,
;;; and each atom of X is less than the correponding atom of Y.
(ck () (c-compare? '(c-<) '(1 #(5)) '(2 #(6))))
;; ==> #t

;;; Can compare atoms directly.
(ck () (c-compare? '(c-<) '1 '2))
;; ==> #t