Newbie question... I'm struggling to write a rule which boils down to "This or that".
(defrecord This [x])
(defrecord That [y])
(defrule this-or-that
"Print This if fact exists, else print That."
[:or [?x <- This] [?x <- That]]
=>
(println :this-or-that ?x))
(-> (mk-session 'labs-costs-clara.core)
(insert
(->This 1)
(->That 2))
(fire-rules))
This will print twice which isn't what I'm after.
(my real example is patching data... if X exists use it else use some other facts to fill in the gap)
ya, or isnt a xor, it can indeed follow both paths
i tend to think of it as if you had two disjunct rules
because that is pretty close to what it does
if you want one but not the other...well you are going to want to use two rules with :not
on This
in one and That
on the other
That makes sense. My rules got a bit verbose which is what got me wondering.
Thanks
The only alternative I could imagine was some kind of maybe
accumulator
(e.g. distinct but expecting one fact)
are you expecting only one, or potentially many
My code was really "if summary value exists use it, else calculate from many other facts" but that's not critical to the general question.
Thanks for your thoughts @zylox that makes me feel more confident
gotcha. id suggest something like
(defrule with-summary
""
[Summary (= ?data data)]
=>
(println ?data))
(defrule without-summary
""
[:not [Summary]]
[?others <- (acc/all) :from [SecondaryFacts]]
=>
(println ?others))
thenbest of luck
Thank you
without all the horrible syntax errors i just edited out haha