2011-07-05 71 views
8

我剛開始學習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")的功能?

回答

11
(defn get-titles [] (map :title (vals distributions))) 
+2

'(圖:標題(瓦爾斯頗))' – amalloy

+0

@ammalloy:謝謝! –

5

或者:(for [[k v] distr] (:title v))