File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change 39
39
"
40
40
(:refer-clojure :rename {bound-fn* clj-bound-fn*
41
41
binding clj-binding
42
- with-bindings* clj-with-bindings*}))
42
+ with-bindings* clj-with-bindings*
43
+ with-bindings clj-with-bindings}))
43
44
44
45
(defn- dynj-name [dynj]
45
46
#_ (symbol (name (ns-name (:ns (meta dynj))))
105
106
(assert (every? dynj-var? (keys binding-map)))
106
107
(clj-with-bindings* binding-map thunk))
107
108
109
+ (defmacro with-bindings
110
+ " Executes `body` using implementations defined via a map of dynj vars."
111
+ [binding-map & body]
112
+ `(with-bindings* ~binding-map (fn [] ~@body)))
113
+
108
114
(defn merge-dynjs
109
115
" Like merge, but asserts that all keys are dynj vars, and the same
110
116
vars are not bound to different implementations."
Original file line number Diff line number Diff line change 45
45
; ; expects a thunk
46
46
(fn [] (foo 3 ))))))
47
47
48
+ (t/deftest with-bindings-test
49
+ (t/is
50
+ (= 11
51
+ (dynj/with-bindings
52
+ {#'foo (fn [x] (+ x 4 ))}
53
+ (foo 7 )))))
54
+
48
55
(dynj/defn-dynj bar [arg]
49
56
(* 3 arg))
50
57
56
63
b2 {#'bar (fn [x] (str x " foo" ))}
57
64
bindings (dynj/merge-dynjs b1 b2)]
58
65
(t/is " 17foo"
59
- (dynj/with-bindings* bindings
60
- (fn []
61
- (bar (foo 16 )))))
66
+ (dynj/with-bindings bindings
67
+ (bar (foo 16 ))))
62
68
(dynj/merge-dynjs b1 b2))
63
69
(t/is
64
70
(thrown? AssertionError
You can’t perform that action at this time.
0 commit comments