Hi,

Am 02.01.2009 um 03:37 schrieb Eric Tschetter:

When you look at the backtrace of the exception you will find
(very far down the trace) lines like "caused by..". There you
normally find more useful information than "ExceptionInInitializer".

user=> (defmacro tracefn [function-name]
"Creates trace logging of calls to a function."
`(def ~function-name (let [old-function# ~(eval function-name)]

You don't want eval here. Only ~function-name. If you use eval
somewhere it's almost always wrong. There are uses for eval,
but they are veeery rare.

  (fn [& args#]
      (println args#)
      (print "  ")
      (let [ret-val# (apply old-function# args#)]
   (println ret-val#)
   ret-val#)))))

Maybe you want to use prn instead of println?

user=> (defn poor-mans-multiply [x y]
(if (> x 0)
    (+ y (poor-mans-multiply (dec x) y))
  0))

Also not related and I suspect this to be just an example, but
nevertheless: the JVM does not support tail call optimisation.
So this function will blow up the stack for sufficiently large
values of x. You might want to look at the trampoline utility
function.

Hmm.. or just for fun rewrite it using the sequence library
of Clojure. :)

(defn poor-mans-multiply
  [x y]
  (apply + (take x (repeat y))))

And finally you might find this useful:
http://groups.google.com/group/clojure/browse_frm/thread/3ea8777880231e18/6fd1b352ac1a6744?lnk=gst&q=trace#6fd1b352ac1a6744

Sincerely
Meikel

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to