3 ms·
vectors don't use equal comparison whereas strings do This behavior is required by the specification. From https://www.lispworks.com/documentation/HyperSpec/Bo
by koito17 2y ago
vectors don't use equal comparison whereas strings do
This behavior is required by the specification. From https://www.lispworks.com/documentation/HyperSpec/Body/f_equal.htm https://www.lispworks.com/documentation/HyperSpec/Body/f_equ... ,
Two arrays are equal only if they are eq, with one exception: strings and bit vectors are compared element-by-element (using eql).
What makes strings and bit vectors special, in my opinion, is that they are homogeneous arrays. Heterogeneous arrays aren't something that I often use outside of Clojure (usually because they are awkward to use in statically typed languages).
The specification allows (eq 1 1) to be false
Because the specification doesn't limit the magnitude of numbers nor state how they should be stored in memory. The scenario you've described requires an implementation that intentionally makes every number a bignum or an instance of a class (like Smalltalk).
- kazinator 2y agoLists can be heterogeneous and often are, yet equal recurses on them. If you have list-based code that uses equal, you have extra work to do if you want to convert it to vectors. Vectors comparable with equal make good hash table keys when heterogeneous keys are needed which don't need the structural flexibility of lists.