This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-01-11
Channels
- # announcements (16)
- # aws (17)
- # babashka (25)
- # beginners (60)
- # calva (40)
- # cider (3)
- # clara (4)
- # clj-kondo (24)
- # clojure (16)
- # clojure-austin (3)
- # clojure-dev (23)
- # clojure-europe (33)
- # clojure-nl (2)
- # clojure-norway (7)
- # clojure-uk (4)
- # clojurescript (39)
- # clr (108)
- # conjure (10)
- # cursive (12)
- # datalevin (7)
- # editors (2)
- # events (1)
- # fulcro (24)
- # graalvm (3)
- # introduce-yourself (8)
- # london-clojurians (2)
- # malli (18)
- # meander (6)
- # missionary (10)
- # nbb (16)
- # off-topic (19)
- # polylith (1)
- # portal (4)
- # rdf (1)
- # reitit (4)
- # remote-jobs (3)
- # shadow-cljs (10)
- # xtdb (12)
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.
CheersUsing 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!!
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…