tags:

views:

119

answers:

1

How could I call a function with a string? e.g. something like this:

(call "zero?" 1) ;=> false
+11  A: 

Something like:

(defn call [^String nm & args]
    (when-let [fun (ns-resolve *ns* (symbol nm))]
        (apply fun args)))
Alex Ott
Thanks, `ns-resolve` in particular was what I was looking for.
Ashley Williams
it's better also to combine ns-resolve together with fn? to check, that symbol is function
Alex Ott