Clojure - Changing the value of an atom in a different function
<p>I know that Clojure is all about immutable data. So if you have an atom (say with value 0), the way to change it's value is to de-reference the atom and use swap! or reset! (say now with value 1). However, globally the atom still has value 0 and in the specific reset! or swap! function it has value 1. (I believe this to be correct). My question is, can I have another function that changes the value of the atom which is at 1.</p>

<p>More clearly</p>

<pre><code>(def table-data {:headers ["RIC-Code" "Isin" "Currency" "Description"]
                 :rows []})

(defonce fields (atom {}))
(defonce errors (atom nil))
(defonce isin (atom "test")
(defonce tdata (atom table-data))


(defn get-ric [ric isin]
  (GET "/search-isin"
       {:params {:ric ric}
        :headers {"Accept" "application/transit+json"}
        :handler #(do
                   (.log js/console (str "get-msg response : " %))
                   (reset! isin %)
                   (reset! tdata {:headers ["RIC-Code" "Isin" "Currency" "Description"]
                                  :rows    @isin}))}))



(defn replace-value [struct]
  (walk/prewalk-replace {"id" "name"} struct))
(defn isin-form2 [isin]
  [:div.content
   [errors-component errors :server-error]
   [:div.form-group
    [errors-component errors :name]
    [:p "Enter RIC-Code:"
     [:input.form-control
      {:type      :text
       :name      :ric
       :on-change #(swap! fields assoc :ric (-&gt; % .-target .-value))
       :value     (:ric @fields)}]]
    [errors-component errors :message]
    [:input.btn.btn-primary
     {:type     :submit
      :on-click #(do
                  (get-ric (:ric @fields) isin))
      :value    "Search RIC-Code"}]
    [rt/reagent-table tdata]
    [:input.btn.btn-primary
     {:type     :submit
      :on-click #(do
                  (reset! tdata {:headers ["RIC-Code" "Isin" "Currency" "Description"]
                                 :rows    (swap! isin (replace-value %))}))
      :value    "Change"}]]])
</code></pre>

<p>What the above code does, is in isin-form2, it takes an initial value, and sets in into fields with keyword ric. The first button calls the get-ric function and returns tdata. (In get-ric the isin is an atom that is a vector of vectors ie [["id" ...] [...] ... [...]]) What I want the second button to do is swap the value id for name, using replace-value. However in the second button when I try to swap! the value of the isin it is not changing</p>