| Paste number 67182: | jcall jfn |
| Pasted by: | rhickey |
| When: | 1 year, 11 months ago |
| Share: | Tweet this! | http://paste.lisp.org/+1FU6 |
| Channel: | #clojure |
| Paste contents: |
(defn jcall [obj name & args]
(clojure.lang.Reflector/invokeInstanceMethod obj (str name)
(if args (to-array args) clojure.lang.RT/EMPTY_ARRAY)))
(defn jfn [name]
#(apply jcall %1 name %&))
((jfn 'substring) "fred" 2 3)
((jfn 'toUpperCase) "fred") Annotations for this paste:
| Annotation number 1: | fn from method name without reflection |
| Pasted by: | joubert |
| When: | 1 year, 11 months ago |
| Share: | Tweet this! | http://paste.lisp.org/+1FU6/1 |
| Paste contents: |
(defmacro getFnFromMethodName "Given a 'methodName', returns a function that invokes that method." [methodName] `(fn [target# val#] (. target# ~(symbol methodName) val#)))