Is there a way to use :keys[a b c]
inside of a list of constraints to avoid doing (`?something (:a this))`
i believe so, let me see if we have doc somewhere
Thank you!
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
@ethanc even if there isn't documentation, if you just happen to know how to do this, it would be greatly appreciated
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")))
Thank you!
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?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.
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