I'm writing a simple game in Java and I want to learn Clojure, so I've decided to refactor my current Java code to Clojure. The problem is that I've coded so much in object-oriented languages that I cannot see how to do it functionally.
To be concrete, I have a
Map<String, Country> inside a singleton class that can be accessed from anywhere to get a Country instance, update it, and put it back into the map. I implemented this the same way in Clojure. For example, to update a country:
(def countries (do-get-countries)) (defn update-country [country] (def countries (assoc countries (get country :name) country)))
Also I've created a
defrecord Country, but I actually modify these records like
(assoc country :name "New name")
These two examples don't look idiomatic in my opinion. Is this actually the correct way to do it in Clojure? If not how would it be more idiomatic?
Thanks in advance!