What are the allowed characters in a Clojure keyword?

后端 未结 4 2134
挽巷
挽巷 2021-02-19 01:27

I am looking for a list of the allowed characters in a clojure keyword. Specifically I am interested to know if any of the following characters are allowed: -

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-19 02:06

    The "correct" answer is documented:

    Symbols begin with a non-numeric character and can contain alphanumeric characters and *, +, !, -, _, and ? (other characters will be allowed eventually, but not all macro characters have been determined). '/' has special meaning, it can be used once in the middle of a symbol to separate the namespace from the name, e.g. my-namespace/foo. '/' by itself names the division function. '.' has special meaning - it can be used one or more times in the middle of a symbol to designate a fully-qualified class name, e.g. java.util.BitSet, or in namespace names. Symbols beginning or ending with '.' are reserved by Clojure. Symbols containing / or . are said to be 'qualified'. Symbols beginning or ending with ':' are reserved by Clojure. A symbol can contain one or more non-repeating ':'s.

    Edit: And further with respect to keywords:

    Keywords are like symbols, except:
    * They can and must begin with a colon, e.g. :fred.
    * They cannot contain '.' or name classes.
    * A keyword that begins with two colons is resolved in the current namespace

提交回复
热议问题