I am very surprised by the behaviour of identical? in clojure.
(def a (map identity [:a :b]))
(identical? (rest a) (rest a)); false
Any idea why identical? returns false?
I am very surprised by the behaviour of identical? in clojure.
(def a (map identity [:a :b]))
(identical? (rest a) (rest a)); false
Any idea why identical? returns false?
On
identical? is the object equality predicate. It returns true if its arguments are the same object/primitive.
Use = over identical?.
identical? is the correct tool when semantics depend on pointer equality, such as testing for an end-of-file sentinel value.
Never use identical? to compare Clojure data structures. Even keywords don't guarantee identical? behaves correctly.
identical?:Since
restcreates a new seq object on each invocation, its results are notidentical?. The following, however, is:Update: As @mfikes pointed out,
restdoes not always create a new seq. It callsISeq.more()internally which is implemented per seq type and might yield different results for lists, vectors, lazy seqs, etc.: