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

Popular posts from this blog

php - URL redirection after form submitted without inherited params -

c# - ReportViewer control - axd url -

c# - must be a non-abstract type with a public parameterless constructor in redis -