I am trying to use a loop recur that creates an empty map inside the loop. For each entry in the loop (loops through a vector of maps) it will see if there is a key in the newly created map that matches the iterated values key and if not create one.
I have created this code:
(def meteor-map (json/read-str (clojure.string/lower-case
(slurp "https://data.nasa.gov/resource/y77d-th95.json"))))
(defn most-falls [values]
(loop [values map count-tracker{}]
(if (empty? values)
(count-tracker)
(do
(def key (keyword (get (first values) "year")))
(if (contains? (first values) key)
(do
(def count-tracker (update count-tracker key inc))
(recur (rest values) count-tracker)
)
(do
(def count-tracker (assoc count-tracker key 1))
(recur (rest values) count-tracker)
)
)
)
)
)
)
(most-falls meteor-map)
However when I call this function and pass in meteor-map (which is a vector of maps) i get an error saying
wrong number of args (0) passed to persistentarraymap
I think this could be due to how I am creating the initial count-tracker object inside the loop creation but I am unsure.
Any ideas?
Thanks
PS am aware this question is a bit vague so any questions just ask!
def, and[values mapinloop), so it's hard to pin down what exactly is going wrong.(count-tracker)supposed to be doing? That's your error. You're trying to call the map without arguments. Once you fix that though,values mapwill give you an error sincemapis a function. I think you just meantvalues values.(count-tracker)? Just returncount-tracker? Then remove the parenthesis around it. Remember, if you surround something in parentheses, you're calling it as a function.