Search code examples
clojure

What is :some-parameter in Clojure?


I'm learning Clojure and I have seen pieces of code with :some-value. What's that ? I saw some code like this

(defn relay [x i]
  (when (:next x)
    (send (:next x) relay i))
  (when (and (zero? i) (:report-queue x))
    (.put (:report-queue x) i))
  x)

if I print the when documentation, I don't find :next there

(doc when)
-------------------------
clojure.core/when
([test & body])
Macro
  Evaluates test. If logical true, evaluates body in an implicit do.
nil

Where is :next definition ?

Thanks!


Solution

  • Those are keywords. Googling what they are can be surprisingly difficult if you don't already know what they are.

    They evaluate to themselves:

    user=> :foo ; evaluates to :foo
    

    They are unique, potentially namespace-qualified identifiers. Which is why they are frequently used as keys in maps:

    (def stuff {:a 1
                :b 2})
    

    They know how to look themselves up (i.e. you can call them as functions):

    (:a stuff) ; 1
    

    ...which is the use-case in your example code. They're quite nice.