Skip to content

Instantly share code, notes, and snippets.

@Chouser
Created October 1, 2010 19:08
Show Gist options
  • Save Chouser/606678 to your computer and use it in GitHub Desktop.
Save Chouser/606678 to your computer and use it in GitHub Desktop.
;; wouldn't it be nice if...
(def-type-multis DataRow
(get-column-names [this])
(get-value [this column-name]))
(defmethods DataRow
clojure.lang.Associative
(get-column-names [this]
(range (count this)))
(get-value [this column-name]
(nth this column-name)))
;; so make it happen...
(defn type* [obj & _] (type obj))
(defmacro def-type-multis [name & methods]
`(do
~@(for [[method-name] methods]
`(defmulti ~method-name type*))))
(defmacro defmethods [name dispatch-value & methods]
`(do
~@(for [[method-name & more] methods]
`(defmethod ~method-name ~dispatch-value ~more))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment