Hey welcome 😊
I looked over the history here (curious about how Clara is being used 🙂 ) and noticed the conversation about anonymous rules in ClojureScript. @weavejester it looks like your understanding is basically correct; in ClojureScript Clara compiles the rules into a rules network at compile time and puts that rules network into the compiled JS code. Since this is done on the JVM the defrule macro puts the cljs rule in the JVM env and associates it with the cljs ns when creating sessions later. Clara decided to group the rules by namespace, but it would also be possible to group in other ways such as ids, regex filters, etc. Some refactoring in https://github.com/cerner/clara-rules/blob/c67b41bc9ea826030ba612579ef21f490433ccd0/src/main/clojure/clara/macros.clj#L205 would help a bit too, that was done for use in some testing internals in Clara that create anonymous rules in ClojureScript. I don’t see a great way around the problem of not being fully dynamic in ClojureScript as in in Clojure though.
Yep, once I saw how Clara worked in ClojureScript, I couldn’t see a way of having anonymous rules either, @wparker.
I think my inclination would be to have a separate registry for the rules, as they’re not really ‘vars’ per se.
But that’s just my preference.
Namespaces fit pretty well with the structure of the code in Cerner consuming Clara, and we wouldn’t want to break that, but supporting other ways or exposing APIs allowing users to group rules in other ways would be reasonable enhancements. Feel free to log an issue to Clara if you have suggestions.
@wparker I support both could be supported, if you supply a keyword instead of a symbol.
(defrule :example/is-important
[SupportRequest (= :high level)]
=>
(println "High support requested!"))
(mk-session :example/*)