Skip to content

Commit 07e0892

Browse files
committed
feat: store handler as symbol instead of var
1 parent 8d6ee9a commit 07e0892

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

src/main/clojure/clara/rules.clj

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,19 +250,20 @@
250250
\"HVAC repairs must include a 27B-6 form.\")))
251251
252252
See the [rule authoring documentation](http://www.clara-rules.org/docs/rules/) for details."
253-
[name & body]
253+
[rule-name & body]
254254
(let [doc (if (string? (first body)) (first body) nil)
255-
rule (dsl/build-rule name body (meta &form)) ;;; Full rule LHS + RHS
256-
rule-action (dsl/build-rule-action name body (meta &form)) ;;; Only the RHS
255+
rule (dsl/build-rule rule-name body (meta &form)) ;;; Full rule LHS + RHS
256+
rule-action (dsl/build-rule-action rule-name body (meta &form)) ;;; Only the RHS
257257
rule-node (com/build-rule-node rule-action) ;;; The Node of the RHS
258258
{:keys [bindings production]} rule-node
259-
rule-handler (com/compile-action-handler name bindings
259+
rule-handler (com/compile-action-handler rule-name bindings
260260
(:rhs production)
261261
(:env production))
262-
name-with-meta (vary-meta name assoc :rule true :doc doc)] ;;; The compiled RHS
262+
name-with-meta (vary-meta rule-name assoc :rule true :doc doc)
263+
handler-name (symbol (name (ns-name *ns*)) (name rule-name))] ;;; The compiled RHS
263264
`(defn ~name-with-meta
264265
([]
265-
(assoc ~rule :handler #'~name-with-meta))
266+
(assoc ~rule :handler '~handler-name))
266267
(~@(drop 2 rule-handler)))))
267268

268269
(defmacro defquery

src/main/clojure/clara/rules/compiler.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1531,7 +1531,7 @@
15311531
(if expr-cache
15321532
(let [cache-key (str (md5-hash expr) (md5-hash compilation-ctx))
15331533
compilation-ctx (assoc compilation-ctx :cache-key cache-key)
1534-
compiled-handler (some-> compilation-ctx :compile-ctx :production :handler deref)
1534+
compiled-handler (some-> compilation-ctx :compile-ctx :production :handler resolve)
15351535
compiled-expr (or compiled-handler
15361536
(cache/lookup expr-cache cache-key))]
15371537
(if compiled-expr

src/test/clojure/clara/test_engine.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
[criterium.core :refer [report-result
1313
with-progress-reporting
1414
quick-benchmark]]))
15+
1516
(defrule test-slow-rule-1
1617
"this rule does some async work using go block"
1718
[:number [{:keys [value]}]

0 commit comments

Comments
 (0)