Clojure def vs defn for a function with no arguments

后端 未结 4 1257
萌比男神i
萌比男神i 2021-02-01 01:19

I have written a program in clojure but some of the functions have no arguments. What would be the advantages of coding such functions as a \"def\" instead of a \"defn\" with no

4条回答
  •  半阙折子戏
    2021-02-01 01:35

    defs are evaluated only once whereas defns (with or without arguments) are evaluated (executed) every time they are called. So if your functions always return the same value, you can change them to defs but not otherwise.

提交回复
热议问题