Skip to content

Instantly share code, notes, and snippets.

@amalloy
Created September 29, 2010 08:02
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 amalloy/602441 to your computer and use it in GitHub Desktop.
Save amalloy/602441 to your computer and use it in GitHub Desktop.
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