I have a function a defined as
(defn a [] "Hello")
I have another variable which b
(def b "a")
I would like to call the function represented by the string value of 'b', ie 'a' should be called. How do I do that?
You need to convert it into a symbol
and then resolve
it:
user=> ((resolve (symbol b)))
"Hello"
user=> ((-> b symbol resolve))
"Hello"
Just to clarify a little, here is a slightly more verbose solution:
(let [func (-> b symbol resolve)]
(func arg1 arg2 arg3)) ; execute the function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With