-
-
Save mefesto/91e161a8c5da96faa217 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
(ns mefesto.test.arglist) | |
(defn wrapper* [f] | |
(fn [& more] | |
(println "do this") | |
(println "do that") | |
(let [res (apply f more)] | |
(println "do other") | |
(println "clean up") | |
res))) | |
(defmacro defthing [name & opts] | |
(let [docstring (if (string? (first opts)) (first opts)) | |
opts (if (string? (first opts)) (next opts) opts) | |
fnspecs (cond | |
(vector? (first opts)) ; assume single arglist style | |
(list opts) | |
(list? (first opts)) ; assume multi arglist style | |
opts | |
:else | |
(throw (IllegalStateException. "Invalid fnspec arglist"))) | |
args (map first fnspecs) | |
metadata {:doc docstring :arglists (cons 'quote (list args))}] | |
`(def ~(with-meta name metadata) | |
(wrapper* (fn ~@fnspecs))))) | |
(comment | |
(use :reload 'mefesto.test.arglist) | |
(defthing my-test | |
"my-test docstring" | |
([x] x) | |
([x y] [x y]) | |
([x y & more] [x y more])) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment