Clojure - 獲取 Map 的值



返回對映到鍵的值,如果鍵不存在則返回 not-found 或 nil。

語法

以下是語法。

(get hmap key)

引數 - ‘hmap’ 是雜湊鍵和值的對映。‘key’ 是需要返回值的鍵。

返回值 - 返回傳遞給 get 函式的鍵的值。

示例

以下是 Clojure 中 get 的示例。

(ns clojure.examples.example
   (:gen-class))
(defn example []
   (def demokeys (hash-map "z" "1" "b" "2" "a" "3"))
   (println demokeys)
   (println (get demokeys "b")))
(example)

輸出

以上程式碼產生以下輸出。

{z 1, b 2, a 3}
2
clojure_maps.htm
廣告

© . All rights reserved.