Short Answer
See this question: When to use a Var instead of a function?
Longer Answer
You are using the atom in a non-standard way. I think the following is closer to what you want:
(defn f1 [] "#1")
(defn f2 [] "#2")
(def my-fn (atom f1))
(println :1 (@my-fn))
(reset! my-fn f2)
(println :2 (@my-fn))
Generates:
:1 #1
:2 #2
Longest Version
This example shows the difference between copying a function vs copying the var that points to the function:
; This will not work, since his-fn saves a ref to the
; immutible "All yours baby!" function
(newline)
(println "-----------------------------------------------------------------------------")
(defn your-fn [] (println "All yours baby!"))
(your-fn) ;=> "All yours baby!"
(def his-fn your-fn)
(his-fn) ;=> "All yours baby!"
(defn your-fn [] (println "And it still is!"))
(his-fn) ;=> "All yours baby!"
; This will work, since both his-fn and her-fn save a reference
; to the var `your-fn`, which in turn points to first to
; one function and then to a second function.
(newline)
(println "-----------------------------------------------------------------------------")
(defn your-fn [] (println "All yours baby!"))
(your-fn)
(def his-fn (var your-fn))
(def her-fn #'your-fn)
(his-fn)
(her-fn)
; change what var "your-fn" points to
(defn your-fn [] (println "And now you belong to me..."))
(his-fn)
(her-fn)
With results:
;-----------------------------------------------------------------------------
;=> All yours baby!
;=> All yours baby!
;=> All yours baby!
-----------------------------------------------------------------------------
;=> All yours baby!
;=> All yours baby!
;=> All yours baby!
;=> And now you belong to me...
;=> And now you belong to me...
Warning
Having shown how vars behave, please remember it is not good to redefine top-level forms like (def ...)
and (defn ...)
. It is usually best to use an atom, or a local var to hold changing values.