Michel Salim
unread,Jun 16, 2009, 7:13:52 PM6/16/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Clojure
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)