• Clojure
  • 22 lines
  • 6 forks
  • Pasted by anonymous on February 24, 2012
(ns blah.interop
  (:use [clojure.reflect :only (type-reflect)]))

(defn- delegate-method [method]
  (let [name (:name method)
        args (concat ['this]
                     (map #(symbol (str "arg" %))
                                 (range (count (:parameter-types method)))))]
    (list name
          (apply vector args)
          (list (symbol (str "." name)) args))))

(defmacro reify-delegate [type & body]
  (let [info (type-reflect type :ancestors true)
        methods (->> info :members (filter #(contains? % :return-type)))
        implementations (map delegate-method methods)]

; (pprint (macroexpand-1 '(reify-delegate java.lang.Appendable)))

Did you know? CLOSE

  • There are keyboard shortcuts!
    • When Creating A Paste
      • ALT+P Toggle Private
      • CTRL+Enter Create Paste
      • ALT+W Toggle word wrap
    • When Viewing A Paste
      • ALT+G Go to a line
      • ALT+CTRL+E Edit the paste
      • ALT+R Show the raw code
  • There are URL options!
    • When Creating A Paste
      • ?lang=Javascript to default to javascript
    • When Viewing A Paste
      • #L-N Jump to line number N