Created
July 18, 2012 18:43
-
-
Save megakorre/3137983 to your computer and use it in GitHub Desktop.
functional interface implementation in clojure
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 fi | |
[interface args & code] | |
(let [interface-type (.getMapping *ns* interface) | |
methods (-> (.getMethods interface-type) | |
seq) | |
method-sym (.getName (first methods))] | |
(when-not (= (count methods) 1) | |
(throw (new Exception "cant take a interface with more then one method"))) | |
`(proxy [~interface] [] | |
(~method-sym ~args | |
~@code)))) | |
(comment | |
(import java.awt.event.ActionListener) | |
(def action (fi ActionListener [e] | |
(println "hello world")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment