I have been using the following function a lot:
(defn set-var-root [v value]
(alter-var-root v (constantly value)))
And I have seen this pattern a lot in other code too. It is like an idiom if I understand correctly.
Why is it not in clojure.core?
Might it be a good addition and if not, why not?
I have asked in clojurians slack and was pointed out to
(.bindRoot avar value)
Which I didn't know before also. But again the question why is it not part of the public API? Is there something wrong with using vars like this?
To give some context, I am developing a game engine and on app start I am setting global vars for input, graphics context, etc.
https://github.com/damn/gdl/blob/main/src/gdl/game.clj#L13
(defn- load-gdx-globals []
(set-var-root #'gdl.app/app Gdx/app)
(set-var-root #'gdl.files/files Gdx/files)
(set-var-root #'gdl.graphics/graphics Gdx/graphics)
(set-var-root #'gdl.input/input Gdx/input))