Skip to content

Instantly share code, notes, and snippets.

@mefesto
Created August 18, 2010 21:05
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 mefesto/91e161a8c5da96faa217 to your computer and use it in GitHub Desktop.
Save mefesto/91e161a8c5da96faa217 to your computer and use it in GitHub Desktop.
(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