I'm learning about Clojure using the book Seven Weeks Seven Languages and I'm feeling like I'm missing the point and/or not getting it.
Question:
Write a function called (collection-type col) that returns :list, :map, or :vector based on the type of collection col.
My Solution:
(defn collection-type
"returns collection type for list map or vector"
[col]
(def look-up {:list "class clojure.lang.PersistentList", :map "class clojure.lang.PersistentArrayMap", :vector "class clojure.lang.PersistentVector"})
(if (= (look-up :list) (str (type col))) (println :list))
(if (= (look-up :map) (str (type col))) (println :map))
(if (= (look-up :vector) (str (type col))) (println :vector)))
It works fine but I feel like I'm missing the point, does anyone have any insight/advice/guidance here? It just seems so ugly and in-elegant.
def
can only create globals. As such, it is usually out of place inside a function. – noisesmith