Allow `fspy` to capture freq for exception-throwing bodies

This commit is contained in:
Peter Taoussanis 2013-07-23 14:28:28 +07:00
parent 37f4d35b07
commit 545c278394
1 changed files with 6 additions and 5 deletions

View File

@ -50,11 +50,12 @@
(let [name (utils/fq-keyword name)]
`(if-not *fdata*
(do ~@body)
(let [name# ~name
result# (do ~@body)]
(swap! *fdata* #(assoc-in % [name# result#]
(inc (get-in % [name# result#] 0))))
result#))))
(let [name# ~name
result# (try (do ~@body) (catch Throwable t# {::throwable t#}))
throwable# (and (map? result#) (::throwable result#))]
(swap! *fdata* #(assoc-in % [name# (or throwable# result#)]
(inc (get-in % [name# (or throwable# result#)] 0))))
(if throwable# (throw throwable#) result#)))))
(defmacro f [name & body] `(fspy name ~@body)) ; Alias