clara

http://www.clara-rules.org/
Pieter Slabbert 2020-06-08T13:33:22.126600Z

Hi, We are are going to be using clara rules at work, the example at http://www.clara-rules.org/docs/fact_type_fn_perf/ looks like it will be very useful for part of our system. There are many facts that we will use records for, but there is one kind of fact in particular which we have many different instances of the same fact but each with a different status (there can be quite a few of these statuses) Ideally we don't want to create a new type for each of these statuses. So I would like to be able to create a tuple as shown in the link, but I would also need to be able to write other conditions on it. There is a hint of how to do it on the page right at the bottom, but I can't seem to figure it out. Would anyone be able to provide a fleshed out example with extra conditions?

Felix Holmgren 2020-06-08T14:07:46.129800Z

Hi everyone! ๐Ÿ‘‹ I just (finally) published a podcast interview I did with @ryanbrush two years ago, about Clara. I would think most of it is still as relevant, but if Clara has changed in ways that make what's said in the interview misleading I'd be happy to include pointers in the show notes. In any case, I would of course welcome any feedback/criticism from this community! https://thesearch.space/episodes/2-ryan-brush-on-retaking-rules-for-developers

๐Ÿ‘€ 2
2020-06-08T16:46:56.133800Z

@blob626 youโ€™ve seen this one too http://www.clara-rules.org/docs/fact_type_customization/ ?

2020-06-08T16:47:03.134200Z

the one you linked was more about performance than the feature use itself

ethanc 2020-06-08T18:28:11.135100Z

@blob626, If I remember correctly you should be able to apply constraints to a condition even when using a custom fact type. However, the syntactic sugar that clara provides for field accessors would no longer be available. Meaning that you would have to provide custom destructuring for the fact or have the constraints access the fact via this and drill in that way. For example:

(ns test.rules
  (:require [clara.rules :as r]))


(defrecord SomeFact [id status another-identifier])

(defrecord IncompleteFact [id])

(r/defrule a-rule
  [[SomeFact "id-1"] [{:keys [another-identifier status]}]
    (= ?another-identifier another-identifier)
    (= status "INCOMPLETE")]
  =>
  (r/insert! (->IncompleteFact ?another-identifier)))

(r/defquery get-incomplete-facts
  []
  [?f <- IncompleteFact])

(defn fact-type-fn
  [fact]
  (if (instance? SomeFact fact)
    [`SomeFact (:id fact)]
    (type fact))) 

(defn run-test
  []
  (-> (r/mk-session [a-rule get-incomplete-facts]
                    :fact-type-fn fact-type-fn)
      (r/insert (->SomeFact "id-1" "INCOMPLETE" "external-id"))
      (r/fire-rules)
      (r/query get-incomplete-facts)))
Specifically,
[{:keys [another-identifier status]}]

๐Ÿ‘ 1
apbleonard 2020-06-08T19:56:00.136300Z

Clara Rules has a mention in Rich Hickey's HOPL IV "A History of Clojure" paper! ๐Ÿ™‚ https://clojure.org/about/history

โค๏ธ 3
ethanc 2020-06-08T20:21:55.136500Z

๐Ÿ˜ฎ

2020-06-08T22:29:05.137Z

thanks for making the example @ethanc

2020-06-08T22:29:09.137200Z

perhaps our docs are too weak on this

2020-06-08T22:29:15.137400Z

I need to re-read through

2020-06-08T22:29:36.137900Z

and clara is in the history paper? wow, Iโ€™ve been meaning to read it. Claraโ€™s officially famous ๐Ÿ˜œ\

๐Ÿ™‚ 2