What is the :: used for in clojure?

Clojure

Clojure Problem Overview


I understand keywords in Clojure being :keyword. But what is the :: used for? Why does it look like it has a binding?

user=> :foo
:foo
user=> ::foo
:user/foo

Clojure Solutions


Solution 1 - Clojure

The double colon is there to fully qualify keywords with your current namespace. This is intended to avoid name clashes for keywords which are meaningful for different libraries. Without fully qualified keywords you might accidentally overwrite some values in a map and break compatibility with a library.

Solution 2 - Clojure

As now documented for Clojure as well as for ClojureScript, :: keywords can also be used to resolve namespace aliases. For example, ::foo/bar will evaluate to :clojure.core/bar if foo is an alias of clojure.core. Reader exception is thrown if foo does not resolve to a namespace.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioncarinmeierView Question on Stackoverflow
Solution 1 - ClojureskuroView Answer on Stackoverflow
Solution 2 - ClojureShaun LebronView Answer on Stackoverflow