2010-10-03 28 views

cevap

14

Basit cevap:

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

(call "zero?" 1) 
;=> false 

Sadece eğlence için:

(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) 
28

şey gibi:

(defn call [^String nm & args] 
    (when-let [fun (ns-resolve *ns* (symbol nm))] 
     (apply fun args))) 
+1

teşekkür, 'ns-resolve' içinde özellikle aradığım şeydi. –

+6

ns-resol'ü fn ile birlikte birleştirmek daha mı iyi? kontrol etmek, bu sembolün işlevi –

İlgili konular