in Clojure, why have Strings, Keywords AND Symbols?

前端 未结 2 1987
说谎
说谎 2020-12-15 17:54

I\'m in the process of learning Clojure and I can\'t understand some language design decisions: Why does a language with immutable Strings like Clojure also needs Keywords a

2条回答
  •  再見小時候
    2020-12-15 18:13

    I think Clojure values "practicality" (if that's the correct word) somewhat more than "purity". This can be seen in the fact, Clojure has syntax for maps, vectors and sets in addition to lists, and is using it to define the language. In Scheme, which is much more concerned with purity (IMO), you only have syntax for lists.

    As Arthur Ulfeldt points out strings, keywords and symbols have their intended use cases. And using them as intended makes it easier to read Clojure code. It's similar to what is happening with HTML 5, which adds semantic mark-up. Things like

    and
    , which you can represent with
    and
    in HTML 4.

    OH, and you're wrong about comparing strings just by identity. This is guaranteed to work only for interned strings. And you don't want to intern too many strings as they are stored into the so called permgen, which is quite limited in size and never garbage collected.

提交回复
热议问题