Hi, Am 02.01.2009 um 18:00 schrieb Eric Tschetter:
From the Repl try: (.printStackTrace *e)
The thing is, I want to store the actual *function* not the symbol referencing the function (the symbol's reference changes after the macro is evaluated).
1:10 user=> (defmacro tracefn "Creates trace logging of calls to a function." [function-name] `(def ~function-name (let [old-function# ~function-name] (fn [& args#] (println args#) (print " ") (let [ret-val# (apply old-function# args#)] (println ret-val#) ret-val#))))) nil 1:21 user=> (defn foo [x] (inc x)) #'user/foo 1:22 user=> (macroexpand-1 '(tracefn foo))(def foo (clojure.core/let [old-function__28__auto__ foo] (clojure.core/fn [& args__29__auto__] (clojure.core/println args__29__auto__) (clojure.core/print " ") (clojure.core/let [ret- val__30__auto__ (clojure.core/apply old-function__28__auto__ args__29__auto__)] (clojure.core/println ret-val__30__auto__) ret- val__30__auto__))))
1:23 user=> (foo 1) 2 1:24 user=> (tracefn foo) #'user/foo 1:25 user=> (foo 1) (1) 2 2
Is that just to give the user flexibility on whether they want to flush on new line? Or is there some other reason to choose prn over println?
1:6 user=> (println "foo") foo nil 1:7 user=> (prn "foo") "foo" nil 1:8 user=> (println \space) nil 1:9 user=> (prn \space) \space nil I would prefer prn. Sincerely Meikel
smime.p7s
Description: S/MIME cryptographic signature