Fork me on GitHub
#clara
<
2023-01-11
>
pdmct05:01:59

Hi, Happy new year to everyone. A quick question is it possible to get the name of the rule that is being fired from inside the rule? I want to add the name of the rule that has fired to the record that I am inserting so I can see which rule resulted in the insertion, rather than having to look through a trace or whatever. And I would rather not have to re type the rule name inside every rule … we have a lot of rules. So I can just add my something like the following to each of my insert!s on RHS:

(insert! (->MyObject :a :b :c <get_rule_name_magic>))
I have found a trick on the inter webs on how to do this in a function so I will have that a try and see if it works: https://groups.google.com/g/clojure/c/Zpc2yaZDxqA?pli=1 Just thought I would ask here and see if there are any other approach’s people have found. Cheers

pdmct06:01:56

Using the approach in the link above — results in a value for the rule name of something like: clara.rules.engine/fire-rules*/fn—18809/fn—18810. Which is not super useful , so any other hints, ideas would be appreciated!!

ethanc17:01:32

A rule is just a human readable form of a set of nodes in the network, under the hood it could be several functions spread across several nodes. dynamically capturing the function name as you have demonstrated, probably isn’t valuable. I don’t believe that this would be considered a formal contract with Clara so buyer beware…. but there exists a dynamic variable(rule-context): https://github.com/cerner/clara-rules/blob/main/src/main/clojure/clara/rules/engine.cljc#L228-L229 During rules execution its bound with a map containing the production node being executed: https://github.com/cerner/clara-rules/blob/e86dcd4f0224d966c1bd82043e79cf59c96136bf/src/main/clojure/clara/rules/engine.cljc#L1789-L1793 That ProductionNode has a field “production” which is the rule in question, that rule should have a name: https://github.com/cerner/clara-rules/blob/e86dcd4f0224d966c1bd82043e79cf59c96136bf/src/main/clojure/clara/rules/engine.cljc#L336 Again, this is all internal details to how Clara operates today and no strict contract exists here…

pdmct20:01:48

Thanks will take a look