-
-
Save ordnungswidrig/82de4ebfd6a331c029a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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