I've often felt the need to enable tracing on some particular
functions, but do not really want to modify their definitions and then
add a requirement on clojure.contrib.trace. Here's a macro I came up
with, inspired by the tracing syntax in Chez Scheme:
(defmacro dotrace
"Given a sequence of functions to trace, evaluate the given
expressions
in an environment in which the given functions have tracing enabled"
[fns & exprs]
(if (empty? fns)
`(do ~...@exprs)
(let [func (first fns)
fns (next fns)]
`(let [f# ~func]
(binding [~func (fn [& args#] (trace-fn-call '~func f# args#))]
(dotrace ~fns ~...@exprs))))))
I've tested and it appears to work fine (both from REPL -- there was a
slight hiccup earlier when I was testing; turns out that my
CLOJURE_EXT directory contains a JAR file from an Enclojure project
that bundles its own clojure-contrib.jar; and from Slime).
If others find it useful, I'd love for this to be added. Please let me
know if there are any improvements I could make -- this is my first
Clojure macro, so I'm sure I'm doing some non-idiomatic things.
Thanks,
--
Michel S.
(my contributor agreement should be with Rich already)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---