Why does using keywords or symbols as functions to lookup values from maps work?

后端 未结 3 1046
你的背包
你的背包 2020-12-06 04:10

Quoting from Joy of Clojure, section 4.3.1--

Because keywords are self-evaluating and provide fast equality checks, they\'re almost always us

3条回答
  •  广开言路
    2020-12-06 05:13

    Citation from official documentation:

    Keywords implement IFn for invoke() of one argument (a map) with an optional second argument (a default value). For example (:mykey my-hash-map :none) means the same as (get my-hash-map :mykey :none). See get.

    And Clojure can call keyword as function, because it implements same interface as function. The same is for symbols...

提交回复
热议问题