如果我定义了以下地图,我刚开始学习Clojure:
(def distributions {:normal {:title "Normal" :mean 0 :sd 1}
:beta {:title "Beta" :a 1 :b 3}
:gamma {:title "Gamma" :rate 1/2 :shape 1}})
我如何写(defn get-titles [] ...)
一个会返回的函数
("Normal", "Beta", "Gamma")
?
答案 0 :(得分:11)
(defn get-titles [] (map :title (vals distributions)))
答案 1 :(得分:5)
或者:(for [[k v] distr] (:title v))