robert-hooke icon indicating copy to clipboard operation
robert-hooke copied to clipboard

hooks don't work as advertised on clojure.core vars

Open optevo opened this issue 9 years ago • 1 comments

Hi,

There seems to be a small issue with vars in clojure.core:

(defn ping [f & args](println "ping" f args) (apply f args))

(add-hook #'+ #'ping)

(+ 1 1) ;the hook doesn't run

(#'+ 2 2) ;although it does if I use the var

;interning a var with the same name also works: (def - clojure.core/-) (def quot (var-get #'quot)) (intern ns '* (resolve ')) (add-hook #'- #'ping) (add-hook #'quot #'ping) (add-hook #' #'ping) (- 3 3 ) (quot 5 2) (* 4 4)

It's not a big deal as there are numerous easy work arounds. If you don't want to or can't easily fix this, then making a note in the documentation might be a good idea.

If you're wondering why I am hooking core functions, the use cases is this: I wrap the return values of some functions in reference types (delay, future, etc) and I want other functions (e.g. map) to automagically deref them.

optevo avatar Jan 04 '15 23:01 optevo