Skip to content

Instantly share code, notes, and snippets.

@tangrammer
Created November 21, 2014 11:16
Show Gist options
  • Select an option

  • Save tangrammer/f94222bd659c46367fed to your computer and use it in GitHub Desktop.

Select an option

Save tangrammer/f94222bd659c46367fed to your computer and use it in GitHub Desktop.
Almost working macro to get defrecord intercepted
(ns wrapper.in-process
(require [wrapper.aop :refer :all])
(import [wrapper.core Example]))
(defmacro protocol-impl [protocol-definition]
``(defrecord ~(symbol "my-wrapper") [~(symbol "e#")]
~@(let [[type# protocol-functions#] ~protocol-definition]
(conj
(map
(fn [[function-name# function-args#]]
`(~function-name# ~function-args#
(~function-name# ~(symbol "e#") ~@(next function-args#))))
protocol-functions#) type#))
))
(protocol-impl (adapt-super-impls (first (get-methods (Example.)))))
;;=> (clojure.core/defrecord
;; my-wrapper
;; [e#]
;; wrapper.core.Welcome
;; (say_bye [this# a# b#] (say_bye e# a# b#))
;; (greetings [this#] (greetings e#)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment