Fork me on GitHub
#clara
<
2018-08-09
>
wparker16:08:56

@jeremy642 @mikerod this might be useful in combination with Mike’s suggestion of using Java objects as facts that you could translate into Clojure objects if desired: http://www.clara-rules.org/docs/java/ Basically Clara has a wrapper that you can use instead of needing to do the interop glue work yourself. In case you weren’t already aware.

wparker16:08:44

Also FYI Clara will use the bean properties on Java objects to allow field use by name in the DSL, that isn’t just for records

wparker16:08:39

i.e. Object A has a “getB” method, you can just refer to “b” in a condition like [A (= b some-value)]

jeremy16:08:09

My rules implementation does not use Java types for fact types. So the question was how to handle the interop.

jeremy16:08:24

(defrule new-return
  "The service is a new return."
  [:approval-status (= (:value this) :new-return)]
  =>
  (insert! {:type :rule/result
            :id :new-return
            :priority 2}))

jeremy16:08:27

(r/insert {:type :approval-status :value :new-return})
is how I would insert using clojure.

jeremy16:08:43

Without changing the rules to beans or defining the facts with defrecords. The big ?? was how to allow Java to create maps with the keyword format that matched the rules properly.

wparker16:08:53

Perhaps write a rule that matches on Java maps and translates them, then inserts the result? That way you could just insert the Java map into the session

wparker16:08:32

That rule could then just not do anything if only Clojure maps were in the session

jeremy16:08:06

So that's one thought. I could write new rules that's sole job was to convert say a Java map if matches to a clojure map.

jeremy16:08:29

I haven't progressed on any implementation yet. Been busy but I have some ideas to play with.

jeremy16:08:31

:thumbsup:

wparker17:08:26

Note that Clojure maps also implement Java’s map, so you’d need to guard against an infinite loop there (i.e. require that it a Java Map but not a Clojure map)

jeremy17:08:14

I noticed that clara-rules is on the tech radar by thoughtworks. https://www.thoughtworks.com/radar/languages-and-frameworks

🎉 8
👏 4
mikerod22:08:24

Saw this one back when it was new on there. Pretty cool though!