I started playing with Clojure today and stumbled upon the statement that one could change functions dynamically during runtime. That sounds pretty cool so I wrote a little piece of code using this feature.
(defn ^:dynamic state [x]
(odd x))
(defn even [x]
(if (= x 0)
(println "even")
(binding [state odd] (parity x))))
(defn odd [x]
(if (= x 0)
(println "odd")
(binding [state even](parity x))))
(defn parity [x]
(state (dec x)))
It works out fine, but since I am completly new to Clojure I don't know whether this is
a) clean functional code (since odd and even seem to have sideeffects?)
b) the way changing functions on runtime is supposed to be done
I would appreciate any kind of advice on that! :) -Zakum