Last active
August 29, 2015 14:00
-
-
Save noprompt/11190707 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
(defmacro defntraced | |
"Define a function with it's inputs and output logged to the console." | |
[sym & body] | |
(let [[_ _ [_ & specs]] (macroexpand `(defn ~sym ~@body)) | |
new-specs (map | |
(fn [[args body]] | |
(let [prns (for [arg args] | |
`(js/console.log (str '~arg) "=" (pr-str ~arg)))] | |
(list | |
args | |
`(do | |
(js/console.groupCollapsed (str '~sym " " '~args)) | |
~@prns | |
(let [res# ~body] | |
(js/console.log "=>" (pr-str res#)) | |
(js/console.groupEnd) | |
res#))))) | |
specs)] | |
`(def ~sym (fn ~@new-specs)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment