Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save artfuldev/b2f0e46f4bd96654e2d9659d1453e62f to your computer and use it in GitHub Desktop.
Save artfuldev/b2f0e46f4bd96654e2d9659d1453e62f to your computer and use it in GitHub Desktop.
Clojure Scaffolding for deftype (Christophe Grand) - Show which methods a class implements and for which interfaces
;; Big thanks to Christophe Grand - https://groups.google.com/d/msg/clojure/L1GiqSyQVVg/m-WJogaqU8sJ
(defn scaffold [iface]
(doseq [[iface methods] (->> iface .getMethods
(map #(vector (.getName (.getDeclaringClass %))
(symbol (.getName %))
(count (.getParameterTypes %))))
(group-by first))]
(println (str " " iface))
(doseq [[_ name argcount] methods]
(println
(str " "
(list name (into ['this] (take argcount (repeatedly gensym)))))))))
;;user=>
;;(scaffold clojure.lang.IPersistentStack)
;; clojure.lang.IPersistentStack
;; (peek [this])
;; (pop [this])
;; clojure.lang.IPersistentCollection
;; (count [this])
;; (empty [this])
;; (cons [this G__7960])
;; (equiv [this G__7961])
;; clojure.lang.Seqable
;; (seq [this])
;;nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment