In the Wild

The Clojure language plugin for the LightTable text editor shows off a great example of using an atom to track some fairly complex data.[31] [32] In this case it’s configuration data:

 ;; Lots of code omitted.
 
 (​def​ my-settings (atom {:name ​"clj"
  :dir (fs/absolute-path fs/*cwd*)
  :type ​"lein-light-nrepl"
  :commands [:editor.eval.clj
  :editor.clj.doc
  :editor.cljs.doc
  :editor.clj.hints
 
 ;; Many keywords omitted...
 
  :editor.eval.cljs
  :cljs.compile]}))
 ;; Lots of code omitted.
 
 (​defn​ settings! [setts]
  (swap! my-settings merge setts))

Here we start with an atom containing a map of program settings along with a function that lets us merge new settings into the map. Anytime we need one of the settings, ...

Get Getting Clojure now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.