clojure - When to use alter-var-root with (constantly)? -
i encountered in program:
(defonce foo nil) (alter-var-root #'foo (constantly 4))
since code above uses constantly, there reason prefer simple def, below?
(def foo 4)
is make more consistent defonce, or there downsides using def?
(ns banana) (defonce foo nil) (ns user) (use 'banana) foo ;=> nil (alter-var-root #'foo (constantly 42)) foo ;=> 42 (def foo 50) compilerexception java.lang.illegalstateexception: foo refers to: #'banana/foo in namespace: user
Comments
Post a Comment