Fork me on GitHub
#clara
<
2021-01-25
>
apbleonard16:01:25

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 🙂

mikerod16:01:28

@apbleonard are you using Clara in CLJ or CLJS?

apbleonard16:01:50

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

mikerod16:01:08

Yeah, in CLJ it’s simpler evaluation rules

mikerod16:01:27

when you use defrule it makes a var

mikerod16:01:39

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

mikerod16:01:49

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

mikerod16:01:13

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

👍 3
mikerod16:01:58

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

mikerod16:01:08

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

mikerod16:01:30

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

apbleonard17:01:48

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.

mikerod17:01:45

no problem

apbleonard17:01:27

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.

👍 3