When to use `constantly` in clojure, how and when are its arguments evaluated?

Viewed 1264

In the accepted answer to another question, Setting Clojure "constants" at runtime the clojure function constantly is used.

The definition of constantly looks like so:

(defn constantly
  "Returns a function that takes any number of arguments and returns x."
  {:added "1.0"}
  [x] (fn [& args] x))

The doc string says what it does but not why one would use it.

In the answer given in the previous question constantly is used as follows:

(declare version)

(defn -main
  [& args]
 (alter-var-root #'version (constantly (-> ...)))
 (do-stuff))

So the function returned by constantly is directly evaluated for its result. I am confused as to how this is useful. I am probably not understanding how x would be evaluated with and without being wrapped in `constantly'.

When should I use constantly and why is it necessary?

1 Answers
Related