Fork me on GitHub
#clara
<
2021-04-08
>
PB18:04:34

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

ethanc18:04:30

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

PB18:04:40

Thank you!

PB18:04:21

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

PB18:04:02

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

ethanc18:04:01

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")))

PB18:04:07

Thank you!

PB18:04:19

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?

ethanc19:04:25

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.

ethanc19:04:17

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

👍 3