precept

Preception!
alex-dixon 2017-06-13T22:44:32.441879Z

Hey welcome 😊

2017-06-13T22:49:03.492228Z

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.

2017-06-13T22:51:02.514750Z

Yep, once I saw how Clara worked in ClojureScript, I couldn’t see a way of having anonymous rules either, @wparker.

2017-06-13T22:51:25.519202Z

I think my inclination would be to have a separate registry for the rules, as they’re not really ‘vars’ per se.

2017-06-13T22:51:51.524156Z

But that’s just my preference.

2017-06-13T22:54:15.550675Z

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.

2017-06-13T22:55:10.560777Z

@wparker I support both could be supported, if you supply a keyword instead of a symbol.

2017-06-13T22:56:21.574122Z

(defrule :example/is-important
  [SupportRequest (= :high level)]
  =>
  (println "High support requested!"))

(mk-session :example/*)