Search code examples
clojure

Are keywords with the same name guaranteed to be identical?


Are Clojure keywords with the same name guaranteed to be identical? i.e. Is (identical? :a :a) guaranteed to return true?

What are the precise rules when the keywords of the same name are in different namespaces? For example, (identical? :a ::a) is false. Why?


Solution

  • Keywords which are = are guaranteed to also be identical?, and those which are not = are of course guaranteed to not be identical?.

    :a is different from ::a because the latter has a namespace component and the former doesn't. How could they be identical? Identical means, the very same object reference. Since they have different characteristics they cannot be the same object.