Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the :: used for in clojure?

Tags:

clojure

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 
like image 478
carinmeier Avatar asked Apr 24 '11 14:04

carinmeier


People also ask

What are symbols in Clojure?

In Common Lisp, a "symbol" is a location in memory, a place where data can be stored. The "value" of a symbol is the data stored at that location in memory. In Clojure, a "symbol" is just a name. It has no value.

What is a namespace in Clojure?

Namespaces are mappings from simple (unqualified) symbols to Vars and/or Classes. Vars can be interned in a namespace, using def or any of its variants, in which case they have a simple symbol for a name and a reference to their containing namespace, and the namespace maps that symbol to the same var.

What is Clojure form?

The simplest binding-form in Clojure is a symbol. However, Clojure also supports abstract structural binding called destructuring in let binding lists, fn parameter lists, and by extension any macro that expands into a let or fn .


1 Answers

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.

like image 195
skuro Avatar answered Sep 21 '22 12:09

skuro