Conventions, Style, and Usage for Clojure Constants?

前端 未结 8 1227
余生分开走
余生分开走 2021-02-02 06:48

What are the best practices for defining constants in Clojure in terms of style, conventions, efficiency, etc.

8条回答
  •  孤城傲影
    2021-02-02 07:24

    Clojure has a variety of literals such as:

    3.14159
    :point
    {:x 0 
     :y 1}
    [1 2 3 4]
    #{:a :b :c}
    

    The literals are constant. As far as I know, there is no way to define new literals. If you want to use a new constant, you can effectively generate a literal in the code at compile-time:

    (defmacro *PI* [] 3.14159265358979323)
    (prn (*PI*))
    

提交回复
热议问题