chickadee » vector-lib » vector=

vector= elt=? vec ···procedure

Vector structure comparator, generalized across user-specified element comparators. Vectors a and b are considered equal by vector= iff their lengths are the same, and for each respective elements E_a and E_b, (elt=? E_a E_b) returns a true value. Elt=? is always applied to two arguments. Element comparison must be consistent with eq; that is, if (eq? E_a E_b) results in a true value, then (elt=? E_a E_b) must also result in a true value. This may be exploited to avoid unnecessary element comparisons. (The reference implementation does, but it does not consider the situation where elt=? is in fact itself eq? to avoid yet more unnecessary comparisons.)

If there are only zero or one vector arguments, #t is automatically returned. The dynamic order in which comparisons of elements and of vectors are performed is left completely unspecified; do not rely on a particular order.

Examples:

(vector= eq? '#(a b c d) '#(a b c d))
  ;=> #t
(vector= eq? '#(a b c d) '#(a b d c))
  ;=> #f
(vector= = '#(1 2 3 4 5) '#(1 2 3 4))
  ;=> #f
(vector= = '#(1 2 3 4) '#(1 2 3 4))
  ;=> #t

The two trivial cases.

(vector= eq?)
  ;=> #t
(vector= eq? '#(a))
  ;=> #t

Note the fact that we don't use vector literals in the next two — it is unspecified whether or not literal vectors with the same external representation are eq?.

(vector= eq? (vector (vector 'a)) (vector (vector 'a)))
  ;=> #f
(vector= equal? (vector (vector 'a)) (vector (vector 'a)))
  ;=> #t