clara

http://www.clara-rules.org/
Matthew Pettis 2020-02-07T21:14:43.010200Z

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

Matthew Pettis 2020-02-08T18:26:16.012800Z

fixed and pushed.

Matthew Pettis 2020-02-07T21:15:58.011300Z

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

ethanc 2020-02-07T21:36:09.011500Z

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

ethanc 2020-02-07T21:43:01.011800Z

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 Pettis 2020-02-07T21:44:13.012Z

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 Pettis 2020-02-07T22:39:48.012200Z

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

ethanc 2020-02-07T23:21:22.012400Z

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 🙂