Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clojure can a list be identical to a vector

Tags:

clojure

In REPL, when you input

(= [1 2 3] (list 1 2 3))

You'll get a true. Does it mean that a list can be identical with a vector?

like image 792
Pauli Avatar asked Jan 03 '14 12:01

Pauli


1 Answers

No, a clojure.lang.PersistentList can never be identical? to a clojure.lang.IPersistentVector -- they are different types, and obviously objects of different types can not be the same object. Therefore they can not be identical.

They can, however, be equal. = in Clojure checks equality, not identity, and calls the equals method that every Object has in Java. Both lists and vectors implement equals by determining whether the contents of the list/vector are equal to the contents of the other collection (if the other object is not a collection, it will return false).

like image 69
Nathan Davis Avatar answered Oct 14 '22 19:10

Nathan Davis