Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用函数’;从字符串调用函数;Clojure的名字_Clojure - Fatal编程技术网

使用函数’;从字符串调用函数;Clojure的名字

使用函数’;从字符串调用函数;Clojure的名字,clojure,Clojure,如何使用字符串调用函数?e、 g.类似这样的情况: (call "zero?" 1) ;=> false 比如: (defn call [^String nm & args] (when-let [fun (ns-resolve *ns* (symbol nm))] (apply fun args))) 简单的回答是: (defn call [this & that] (apply (resolve (symbol this)) that))

如何使用字符串调用函数?e、 g.类似这样的情况:

(call "zero?" 1) ;=> false
比如:

(defn call [^String nm & args]
    (when-let [fun (ns-resolve *ns* (symbol nm))]
        (apply fun args)))
简单的回答是:

(defn call [this & that]
  (apply (resolve (symbol this)) that))

(call "zero?" 1) 
;=> false
只是为了好玩:

(defn call [this & that]
  (cond 
   (string? this) (apply (resolve (symbol this)) that)
   (fn? this)     (apply this that)
   :else          (conj that this)))

(call "+" 1 2 3) ;=> 6
(call + 1 2 3)   ;=> 6
(call 1 2 3)     ;=> (1 2 3)

谢谢,
ns resolve
是我特别想要的。把ns resolve和fn结合起来更好?要检查,该符号是function,但在clojurescript中不起作用。