Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Avoid relying on Clojure 1.2 metadata bug.

(def f (with-meta (fn inner [f] (identical? inner f)) {}))

(f f) ; <= true on 1.2!
  • Loading branch information...
commit 7086224d49dc86871cdf1284adb89d38883b6eb6 1 parent 8e2f59f
@technomancy authored
Showing with 11 additions and 10 deletions.
  1. +10 −9 src/robert/hooke.clj
  2. +1 −1  test/robert/test_hooke.clj
View
19 src/robert/hooke.clj
@@ -35,18 +35,19 @@
(defn- join-hooks [original hooks]
(reduce compose-hooks original hooks))
-(defn- run-hooks [hooked original args]
- (apply (join-hooks original @(:robert.hooke/hook (meta hooked))) args))
+(defn- run-hooks [hook original args]
+ (apply (join-hooks original @hook) args))
(defn- prepare-for-hooks [v]
(when-not (:robert.hooke/hook (meta @v))
- (alter-var-root v (fn [original]
- (with-meta
- (fn runner [& args]
- (run-hooks runner original args))
- (assoc (meta original)
- :robert.hooke/hook (atom ())
- :robert.hooke/original original))))))
+ (let [hook (atom ())]
+ (alter-var-root v (fn [original]
+ (with-meta
+ (fn [& args]
+ (run-hooks hook original args))
+ (assoc (meta original)
+ :robert.hooke/hook hook
+ :robert.hooke/original original)))))))
(defn- add-unless-present [coll f]
(if-not (some #{f} coll)
View
2  test/robert/test_hooke.clj
@@ -51,7 +51,7 @@
(is (= :hello (ohai)))
(is @appended))
-(defn another-fn []
+(defn ^{:dynamic true} another-fn []
true)
(deftest test-without-hooks
Please sign in to comment.
Something went wrong with that request. Please try again.