Why does Clojure have “keywords” in addition to “symbols”?

前端 未结 6 1867
暖寄归人
暖寄归人 2020-12-12 11:02

I have a passing knowledge of other Lisps (particularly Scheme) from way back. Recently I\'ve been reading about Clojure. I see that it has both \"symbols\" and \"keywords\"

6条回答
  •  悲哀的现实
    2020-12-12 11:14

    For keywords, hash values are calculated and cached when the keyword is first constructed. When looking up a keyword as a hash key, it simply returns the precomputed hashed value. For strings and symbols, the hash is recalculated on every lookup.

    The why same named keywords are always identical, they contains their own hash values. As search in maps and sets are made from hash keys this envolves better search efficiency in case of numerous searches, not in the search itself.

提交回复
热议问题