I am interested in if it is possible to redefine or override the bindings that are the result of a closure when programming in Clojure?
For example I can do the following just fine:
(defn triple-adder-fn [a b] (fn [x] (+ x a b)))
(def triple-adder (triple-adder-fn 1 2))
(triple-adder 3)
;; => 6
However this creates a local closure that has the bindings of a = 1
and b = 2
and when I call triple-adder
it uses them accordingly.
Now the question is could I do something like the following mock code that would allow me to override those local bindings?
(binding ['a 5
'b 6]
(triple-adder 3))
;; => 14
For my simple example it'd be real easy to call the triple-adder-fn
to get a new function with new bindings. However, for my actual situation, I am in a position where I don't actually control the triple-adder-fn
and only have access to the resulting function.