Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is :fin being used?

Tags:

clojure

In the Clojure Koans :fin is being used in atoms.clj. Here is one example:

(def atomic-clock (atom 0))

  "Atomic atoms are atomic"
  (= 20 (do
          (compare-and-set! atomic-clock 100 :fin)
          @atomic-clock))

I understand that :fin is the new value. But why is it being used instead of number?

I've searched the documentation for :fin being used and cannot find its use other than in the Koans.

Thanks.

like image 385
octopusgrabbus Avatar asked Feb 23 '23 12:02

octopusgrabbus


1 Answers

In Clojure, the colon makes something called a keyword, or a key:

user=> (type :xyz)
clojure.lang.Keyword

Keys are used in maps, because they're easy to check for equality and to convert to strings. You can see that, later in the same file, :fin is used again in a check for equality:

(= :fin (do
        (compare-and-set! __ __ __)
        @atomic-clock)))
like image 186
Matt Fenwick Avatar answered Mar 02 '23 18:03

Matt Fenwick