This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-02-07
Channels
- # announcements (2)
- # babashka (18)
- # beginners (45)
- # bristol-clojurians (1)
- # calva (2)
- # cider (8)
- # clara (8)
- # clj-kondo (4)
- # cljdoc (6)
- # clojure (69)
- # clojure-chennai (1)
- # clojure-dev (21)
- # clojure-europe (3)
- # clojure-gamedev (3)
- # clojure-india (1)
- # clojure-italy (4)
- # clojure-nl (5)
- # clojure-norway (1)
- # clojure-spec (7)
- # clojure-uk (70)
- # clojurescript (122)
- # cloverage (5)
- # cursive (2)
- # data-science (3)
- # fulcro (21)
- # graalvm (3)
- # graphql (14)
- # jackdaw (2)
- # jobs (2)
- # lumo (2)
- # malli (1)
- # mount (1)
- # off-topic (22)
- # re-frame (2)
- # reitit (5)
- # ring (7)
- # shadow-cljs (47)
- # spacemacs (11)
- # tools-deps (127)
- # vim (16)
- # xtdb (9)
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
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
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 thoughthis 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...
... guess i'm a little surprised it worked in the original, now that I see it...
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 🙂fixed and pushed.
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