clara

http://www.clara-rules.org/
PB 2021-04-08T18:14:34.020900Z

Is there a way to use :keys[a b c] inside of a list of constraints to avoid doing (`?something (:a this))`

ethanc 2021-04-08T18:15:30.021600Z

i believe so, let me see if we have doc somewhere

PB 2021-04-08T18:16:40.022500Z

Thank you!

PB 2021-04-08T18:17:21.023100Z

There appears to be afunction called destructure-syms which looks like what I'm looking for. I just don't know how to do this with the sugar

PB 2021-04-08T18:22:02.023900Z

@ethanc even if there isn't documentation, if you just happen to know how to do this, it would be greatly appreciated

ethanc 2021-04-08T18:23:01.024700Z

The doc is alluding me, but the usage would be like this if i remember correctly:

(r/defrule a-rule
  [::some-fact [{:keys [a]}] (= a 12)]
  =>
  (r/insert! (->X "hey")))

PB 2021-04-08T18:24:07.025Z

Thank you!

PB 2021-04-08T18:41:19.026200Z

I found an oddity and I can't quite figure out what is wrong here:

(defrule something
    [:bill [{:keys [direction customer-total]}] (clojure.core/= ?direction direction) (clojure.core/= ?customer-total customer-total)]
    [:direction-looup (clojure.core/= ?outcome (?direction this))]
    =>
    (prn "aaaaacccccbbbbba" ?direction ?customer-total ?outcome))
Works, however:
(defrule something
    [:bill [{:keys [direction customer-total]}] (clojure.core/= ?direction direction) (clojure.core/= ?customer-total customer-total)]
    [:direction-looup (clojure.core/= ?outcome ?direction)]
    =>
    (prn "aaaaacccccbbbbba" ?direction ?customer-total ?outcome))
Throws the error Malformed variable binding for #{?outcome ?direction}. No associated value. I'm not quite sure why this wouldn't work. Can anyone explain it to me?

ethanc 2021-04-08T19:09:25.030300Z

The original rule and the latter differ slightly in the behavior of what is being requested. The first is trying use a prior bound key to get the value out of the direction-lookup fact, where as the latter is simply trying to re-bind the prior bound var with the join. The error doesn’t seem to be describing itself very well, either that or its an edge-case that clara isn’t checking and its failing later in the parse of the rule. Either way, clara doesn’t seem to expect to re-bind vars with joins in this manner.

ethanc 2021-04-08T19:12:17.031300Z

I have also logged an issue to the http://www.clara-rules.org/ site to add documentation on the nature of destructuring in the LHS: https://github.com/cerner/clara-site/issues/39

👍 1