Fork me on GitHub
#clara
<
2021-12-29
>
Swapneil23:12:52

Hi, I've started looking into Clara-Rules as part of a general exploration of Clojure, and I was wondering if it's possible to use it without having to make rulesets (edit: and queries, forgot to mention) as namespace-global variables? It feels incongruous with the style the core library and some external ones encourage. It also on-the-surface seems to have practical costs; for instance, I can't see how you would run multiple parallel simulations of custom-rule insertions and see how they affect firings, which could be convenient for a recommendation or testing system.

mikerod23:12:08

You can specify rules and queries (aka “productions”) to mk-session without anything tied to namespaces or vars

mikerod23:12:53

The productions themself though do get compiled via eval so they do have to be able to resolve symbols against the ns context they are evaled in. But that is likely what you'd already expect

mikerod23:12:48

You can see many examples of this type of ruleset creation in the tests such as https://github.com/cerner/clara-rules/blob/0.21.1/src/test/clojure/clara/test_rules.clj#L91

👍 1
Swapneil00:12:34

Thanks for the link! I was just looking into the docs & tutorial and not finding any method to do this 🙂

ethanc00:12:52

not sure if this would help, but it might also be interesting: http://www.clara-rules.org/docs/ruleforms/

👍 3
Swapneil00:12:25

The pattern was indicated in the above example, but it's nice to know for sure that it works with def'd functions as well.

Swapneil00:12:09

Particularly since now that I check, mk-session is actually a macro, so it was quite plausible that it wouldn't work, prior to your pointing that out!