clara

http://www.clara-rules.org/
apbleonard 2021-01-25T16:35:25.007700Z

Hi there - we're trying to use Clara in the REPL and having problems.... Specifically a REPL-run test that checks the output of a rule doesn't fail when that rule is redefined with errors, as if it is remembering the old rule. Restarting the REPL solves the problem, but wastes time and resources (memory in IntelliJ at least.) This https://github.com/cerner/clara-rules/wiki/Using-Clara-from-the-REPL suggests that a defrule can be re-evaluated in the repl and then clara will use the new version. However looking at the code suggests that rules are set statefully in an atom. It looks also as if that atom might be cleared using (clear-ns-productions!) (https://www.clara-rules.org/apidocs/0.18.0/clojure/clara.rules.html#var-clear-ns-productions.21), - perhaps when this form is evaluated in the namespace in which the rule was defined? But in any case that didn't seem to help for us. Are we missing something obvious? What is the expected way? I could post further codes examples to reproduce etc but wanted to open discussion first. We are using Clara 0.20 🙂

2021-01-25T16:51:28.008Z

@apbleonard are you using Clara in CLJ or CLJS?

apbleonard 2021-01-25T16:51:50.008300Z

CLJ - was just noticing that the stom is cljs ...

apbleonard 2021-01-25T16:51:56.008500Z

atom

2021-01-25T16:52:08.008700Z

Yeah, in CLJ it’s simpler evaluation rules

2021-01-25T16:52:27.008900Z

when you use defrule it makes a var

2021-01-25T16:52:39.009300Z

and if you are using mk-session to automatically scan a namespace to find rule vars

2021-01-25T16:52:49.009600Z

they’ll linger if you remove them in a repl session from the source buffer

2021-01-25T16:53:13.010100Z

you can do something like typical clj idioms for removal if that’s the case, like (ns-unmap *ns* 'rule-name)

1👍
2021-01-25T16:53:58.010500Z

if you redefine the rule with the same name - it’ll overwrite it though

2021-01-25T16:54:08.010800Z

also, you do not have to use Clara in a stateful/var oriented way

2021-01-25T16:54:30.011400Z

you can pass explicit rule/query structures to mk-session instead if that better suits your usage

2021-01-25T16:55:21.011700Z

you can see examples of that such as https://github.com/cerner/clara-rules/blob/main/src/test/clojure/clara/test_rules.clj#L171

apbleonard 2021-01-25T17:10:48.014800Z

Thanks so much for your help. We are clearly not misunderstanding how it should work .... It's still a problem for me .... but now I think the problem maybe our stateful test set up.

2021-01-25T17:16:42.015Z

ok

2021-01-25T17:16:45.015200Z

no problem

apbleonard 2021-01-25T17:35:27.022400Z

D'oh ... we'd reloaded the namespace containing the defrule, but not the namespace which was def-ing up a set of rules for a particular use-case, that was then passed to fire-rules further in. Simple as that :picard-facepalm:. Thanks a lot for your help though.

1👍