Created
September 29, 2010 08:02
-
-
Save amalloy/602441 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
user> (defn setter [[name type]] | |
[(symbol (str "set" name)) ; setName | |
[type] ; pass in an instance to set | |
nil]) ; returns the type | |
#'user/setter | |
user> (defn getter [[name type]] | |
[(symbol (str "get" name)) ; getName | |
[] ; no args to a getter | |
type]) ; returns the type | |
#'user/getter | |
user> (defmacro make-holder-for [class-name fields] ; should be name->type pairs | |
`(gen-interface :name ~class-name | |
:methods [~@(interleave | |
(map getter fields) | |
(map setter fields))])) | |
#'user/make-holder-for | |
user> (make-holder-for Person {name String, age Integer}) | |
Person | |
user> (clojure.core/gen-interface :name Person :methods [[getname [] String] [setname [String] nil] [getage [] Integer] [setage [Integer] nil]]) ; macroexpand not working well for me, so i used slime to expand it into this |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment