Skip to content
This repository has been archived by the owner on Jul 27, 2020. It is now read-only.

Commit

Permalink
Avoid relying on Clojure 1.2 metadata bug.
Browse files Browse the repository at this point in the history
(def f (with-meta (fn inner [f] (identical? inner f)) {}))

(f f) ; <= true on 1.2!
  • Loading branch information
technomancy committed Jun 30, 2011
1 parent 8e2f59f commit 7086224
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions src/robert/hooke.clj
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -35,18 +35,19 @@
(defn- join-hooks [original hooks] (defn- join-hooks [original hooks]
(reduce compose-hooks original hooks)) (reduce compose-hooks original hooks))


(defn- run-hooks [hooked original args] (defn- run-hooks [hook original args]
(apply (join-hooks original @(:robert.hooke/hook (meta hooked))) args)) (apply (join-hooks original @hook) args))


(defn- prepare-for-hooks [v] (defn- prepare-for-hooks [v]
(when-not (:robert.hooke/hook (meta @v)) (when-not (:robert.hooke/hook (meta @v))
(alter-var-root v (fn [original] (let [hook (atom ())]
(with-meta (alter-var-root v (fn [original]
(fn runner [& args] (with-meta
(run-hooks runner original args)) (fn [& args]
(assoc (meta original) (run-hooks hook original args))
:robert.hooke/hook (atom ()) (assoc (meta original)
:robert.hooke/original original)))))) :robert.hooke/hook hook
:robert.hooke/original original)))))))


(defn- add-unless-present [coll f] (defn- add-unless-present [coll f]
(if-not (some #{f} coll) (if-not (some #{f} coll)
Expand Down
2 changes: 1 addition & 1 deletion test/robert/test_hooke.clj
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
(is (= :hello (ohai))) (is (= :hello (ohai)))
(is @appended)) (is @appended))


(defn another-fn [] (defn ^{:dynamic true} another-fn []
true) true)


(deftest test-without-hooks (deftest test-without-hooks
Expand Down

0 comments on commit 7086224

Please sign in to comment.