Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个函数 a 定义为
(defn a [] "Hello")
我有另一个变量 b
(def b "a")
我想调用'b'的字符串值表示的函数,即应该调用'a'。我怎么做?
您需要将其转换为 asymbol然后resolve它:
symbol
resolve
user=> ((resolve (symbol b))) "Hello" user=> ((-> b symbol resolve)) "Hello"
只是为了澄清一点,这里有一个稍微冗长的解决方案:
(let [func (-> b symbol resolve)] (func arg1 arg2 arg3)) ; execute the function