Skip to content

Instantly share code, notes, and snippets.

@ordnungswidrig
Created June 20, 2011 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ordnungswidrig/82de4ebfd6a331c029a2 to your computer and use it in GitHub Desktop.
Save ordnungswidrig/82de4ebfd6a331c029a2 to your computer and use it in GitHub Desktop.
(defmacro reify-generic [protocol f]
;; call reify with f being implementation for every protocol method
...
)
(defmacro make-dispatcher [protocols delegates]
`(letfn [(o# [protocols# delegates#]
(letfn [(delegate# [protocol-f# & args#]
(o# protocols# (map #(apply protocol-f# % (rest args#)) delegates#))))]
(reify-generic delegate# ~@protocols Delegator)))]
(o# (list ~@protocols) (list ~@delegates))))
(make-dispatcher [Proto1 Proto2 Proto3] [implOfProto1 anotherImplOfProto1 anImplOfProto3 ...])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment