technomancy / robert-hooke

Hooke your Clojure functions!
Other
359 stars 25 forks source link

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

Open optevo opened 9 years ago

optevo commented 9 years ago

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.

gfredericks commented 9 years ago

This isn't a problem with clojure.core in particular, but with inlined functions (which are a small subset of clojure.core functions, but are probably rare outside of clojure.core).

My guess is there's no reasonable way to fix this, so documenting would be the only option.