Hello,
I'm trying to intercept each call to a recursive function in order to
insert logging. It works on the first invocation but not on others. What am
I missing?
(defn fact [n]
(if (< n 2)
1
(* n (fact (dec n)))))
; Given function f, returns another function that
; does the same as f but also prints the arguments.
(defn with-logging [f]
(fn [& rest]
(do
(println (str rest))
(apply f rest))))
; Factorial that prints its argument on each call.
(defn fact-with-logging [n]
(binding [fact (with-logging fact)] (fact n)))
; This prints (5) but not (4)...(1). Why?
(fact-with-logging 5)
Roman.
--
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