Fork me on GitHub
#clara
<
2020-02-07
>
Matthew Pettis21:02:43

Because it occurs to me that rules like this are just like basic syllogisms (which I'm sure others have observed long before me here) I put together a dead-simple example of making the rules engine do modus ponens from basic propositional logic. https://github.com/mpettis/clara-lien/blob/master/src/clara_lein/ex07.clj

ethanc21:02:09

I don’t believe that the rhs should be wrapped in a vector, https://github.com/mpettis/clara-lien/blob/master/src/clara_lein/ex07.clj#L28

ethanc21:02:01

my reasoning with this nit is, that the clara wraps the rhs inside a fn and executes it when the lhs is satisfied. basically something like:

(fn [bindings] 
  <original form>)
The inserts! would be considered stateful as the operate on the active session, thus the example still works its just the vector is superfluous. I am just being nit picky though

Matthew Pettis21:02:13

this is good... i was getting some wierd nested results when I ran (but still had right answers). I'll remove and see if that does what's expected; i didn't notice I had wrapped that...

Matthew Pettis22:02:48

... guess i'm a little surprised it worked in the original, now that I see it...

ethanc23:02:22

I should add that clara also wraps the RHS form in a do when you use defrule.

(fn [bindings] 
  (do 
     <form>))
Since clara doesn’t use the returned value from this function, it doesn’t really make a difference, clojure will gladly return a vector with whatever insert! returns. Which is promptly ignored by clara 🙂

Matthew Pettis18:02:16

fixed and pushed.

Matthew Pettis21:02:58

And a slightly more complicated example here too. I'm just experimenting, not saying this is the optimal way to do this, but it is just fleshing out some thoughts and analogies that might be useful for others teaching rules-engines concepts. criticisms welcome. https://github.com/mpettis/clara-lien/blob/master/src/clara_lein/ex08.clj