Created
July 22, 2014 21:35
-
-
Save mkremins/01e1f84b076792e462f5 to your computer and use it in GitHub Desktop.
Define traced function
This file contains hidden or 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
; http://www.reddit.com/r/Clojure/comments/2behsz/clojurescript_debugging_tips/cj4mvok | |
(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