This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-11-30
Channels
- # aws (1)
- # bangalore-clj (2)
- # beginners (64)
- # boot (29)
- # cider (4)
- # clara (14)
- # cljsjs (22)
- # cljsrn (24)
- # clojure (248)
- # clojure-austin (5)
- # clojure-berlin (1)
- # clojure-china (5)
- # clojure-france (1)
- # clojure-greece (1)
- # clojure-italy (2)
- # clojure-korea (6)
- # clojure-russia (76)
- # clojure-spec (2)
- # clojure-uk (59)
- # clojurescript (67)
- # cursive (12)
- # datascript (6)
- # datomic (126)
- # defnpodcast (2)
- # devcards (1)
- # docker (1)
- # events (2)
- # hoplon (14)
- # leiningen (1)
- # luminus (2)
- # midje (2)
- # mount (1)
- # off-topic (4)
- # om (6)
- # onyx (8)
- # parinfer (2)
- # perun (6)
- # proton (5)
- # re-frame (41)
- # reagent (6)
- # ring-swagger (3)
- # rum (1)
- # spacemacs (10)
- # specter (12)
- # yada (25)
I think comparing the result of queries, which will reflect the state of the session before and after you fire rules, is what you’re looking for. So if you have something like
You could query both before and after inserting/retracting + firing rules afterward and see what changed, then dispatch on that
One perhaps non-obvious part of this is when you query the session, you’re not actually performing much work since Clara basically computes the results for queries after fire-rules. When you run a query you’re really basically retrieving the results already computed with a little data manipulation to get just the bindings you use in your query. You can see that implementation at https://github.com/cerner/clara-rules/blob/0.13.0-RC4/src/main/clojure/clara/rules/engine.cljc#L1605
Basically a query and a rule look the same to the rules engine mostly when you look at determine what facts match, a rule just does more things (i.e. it is activated and can insert more facts) once you find matches
You can think of it as large trees of the different node types in engine.cljc where ProductionNode corresponds to rules, QueryNode corresponds to queries, facts are given to the root nodes of these trees and passed down to the leaf nodes, which are ProductionNodes and QueryNodes
Just comparing the results before and after for the queries would work, albeit somewhat inefficiently since you’d be performing work even when nothing at all changed. I think there are ways Clara could return changes in queries more efficiently than that if you were interested in contributing an enhancement like that though.