The standard says that
(equal x y) implies (= (sxhash x) (sxhash y)). Let us check it:
(defun sxhash-test ()
(let ((obj1 (list 1 2 (list 1 1)))
(obj2 (list 1 2 (list 1 2))))
(format t "are objects equal?: ~a~%" (equal obj1 obj2)) ;; => NIL
(format t "are their hashes equal?: ~a~%"(= (sxhash obj1) (sxhash obj2))))) ;; => T
The function equal works as expected but sxhash doesn't. Could you please explain what I am doing wrong? I use SBCL 2.1.9.
Thank you.
The reason why this effect is observed is that two things are required for the values to be
equal:The two lists tested have the same hash, because sxhash doesn't follow nesting. In fact, two structures will always have the same hash.
Why does `sxhash` return a constant for all structs?
As for equal addresses, if I create two values like
'athey in fact turn out to be one item with one address, and is only stored on the first time that it is seen. Whereas(list 1 2 (list 1 1))and(list 1 2 (list 1 2))are different things and are stored at separate addresses.Testing these two lists for equality pass using sxhash, but fail with different addresses.