clojure.contrib.trace enhancement proposal: dotrace

5 views
Skip to first unread message

Michel Salim

unread,
Jun 16, 2009, 7:13:52 PM6/16/09
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)

Stuart Sierra

unread,
Jun 17, 2009, 1:13:06 PM6/17/09
to Clojure
Hi Michel,
Thanks for working on this! I'm going away this week, but I'll be
sure to look at this more closely when I get back. (I wrote the first
c.c.trace, it may have been modified by others since.)
-Stuart Sierra

Michel Salim

unread,
Jun 18, 2009, 2:53:54 AM6/18/09
to Clojure
You're welcome -- the changes are in my github fork of Rich's clojure-
contrib repository,

http://github.com/hircus/clojure-contrib/tree/master

I'll send you a pull request, but it appears that you're not on github
just yet.

--
Michel
Reply all
Reply to author
Forward
0 new messages