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

html5 - What is breaking my page when printing? -

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

ajax - PHP/JSON Login script (Twitter style) not setting sessions -