Search code examples
clojureclojurescript

clojure.core/map behaving in a very surprising manner


(map :one '({:one "one"}))
;; ("one")
(map :name '(r b))
;; (nil nil)
(:name r)
;; "Steve"
(map :one '({:one "one"} {:one "two"}))
;; ("one" "two")
r
;; {:color :red, :name "Steve"}

Map, as you can see here, seems to work as expected for a list of hashmaps but for maps that have been bound to the symbol r and b, map returns nil.

What's going on here, why doesn't map return the correct value for r (Which IMO should be the string "Steve")


Solution

  • Due to '(r b), you're getting the literal symbols r and b, not the maps they resolve to.

    Here you're invoking (:name 'r) and that returns nil.