May not have had enough coffee yet but….how do I do something like this without getting an unbound variable error?
[SomeFact (= a ?a) (= b ?b)]
[:not [:and [Fact1 (= e ?e) (= a ?a)]
[Fact2 (= e ?e) (= b ?b]]]
@alex-dixon I am not sure if @wparker has an issue logged on this subject but odd things can happen sometime in rule compilation due to how Clara compiler converts these Boolean conditions to disjunctive normal form. DNF
So the conditions in the :and are being split by an :or.
I need to look a bit though. Thought the case above was covered.
Basic negated conjunctions should be supported.
Hm ok
By the way is [:not {:exists valid in any way?
@mikerod or is that just equivalent to [:not .. ] ?
Should mean the same thing.
Not sure if it works out that way though. Hah
I’d avoid it.
Some of the negation transformation stuff probably could be improved. I think Will had thoughts on that. I thought he logged an issue. I want to look at what is compiled in your example about to see why you’d have an inbound variable issue
I am not on laptop now. Will be in a few.
(I don’t run Clara repl experiments on my phone unfortunately)
Ok. Started working on spec stuff. Equally stuck there so let me know lol
@alex-dixon See https://github.com/cerner/clara-rules/issues/347
Was just looking at it hah
There are severael issues here. The work that was done before only worked in a fairly small set of situations
So that’s identical
if you can, the workaround is to just move out the conjunction to a different rule I believe
Ok. Let me unwind my attempts that aren’t working and attempt that
(defrule r1
[Fact1 (= e ?e) (= a ?a)]
[Fact2 (= e ?e) (= b ?b)]
=>
(insert! (->Fact3 ?e ?a ?b)))
(defrule r2
[SomeFact (= a ?a) (= b ?b)]
[:not [Fact3 (= a ?a) (= b ?b)]]
=>
(prn {:a ?a
:b ?b
:e ?e}))
I believe that is the extraction
That would pair all Fact1
and Fact2
facts together in the r1
join to make the Fact3
facts
Then r2
would be looking for the non-existence of any of those join results to match the same a
and b
of a SomeFact
fact
Just to clarify my understanding is the :and necessary in r1?
@alex-dixon no, sorry
I just quickly extracted it and forgot I had the :and
there still
I’d leave it out 😛
edited to avoid more confusion
Will try asap. Had to take a break
Thanks for your responses
No problem. That is unfortunate that there are still several caveats to nesting conditions within negation
A lot of the time it can be solved by just pulling everything complex out of the :not
and put it into a different rule where an “bridge”/intermediate fact is used to communicate the logic across the rules
I read through some of the outstanding issues on negation. However, I thought that I remember Will mentioning that he maybe had a few more broad concerns with the current way of dealing with them
Basically, the currently process is to extract rules out from within the :not
transparently
In a way that is similar to what I proposed that you do in the above.
I’m surprised that https://github.com/cerner/clara-rules/issues/347 is still an issue though. I think the fix for it to me seems to be very similar to the work that was done in https://github.com/cerner/clara-rules/pull/342 If so, I think that one would be pretty easy to fix.