Closed tristan-gardner closed 3 years ago
Hi @tristan-gardner
The quick answer is No.
I think, your question is very similar to question asked on issue #140 - support to jump to other rule. You meant to chain a rule within another rule, within another rule, and so on. While "nesting" is a very common language construct (as it mimic the nested "if" capability, so you logically easily makeup your logic), IMHO, its not how an Inference engine works.
As answered in #140 , chaining is your way to achieve similar goal. By chaining, your rule (kind of) giving a clue to the engine to evaluate which rule after a rule gets executed. Its how JBoss/Redhat Drools do it and how Martin Fowler explains it - "An important property of rule engines is chaining - where the action part of one rule changes the state of the system in such a way that it alters the value of the condition part of other rules. Chaining sounds appealing, since it supports more complex behaviors, but can easily end up being very hard to reason about and debug."
One can say, Chaining of rule is trying to implement "nested-if" behavior. While it helps, but if over used, it introduce human comprehension problem as it very hard to reason and debug. Imagine an application that have too many nested complex ifs.
Ok that makes sense and thanks for pointing me to the other answer. @newm4n
Are you able to nest rules within the
then
block of another rule?I want to use this to compose several rules but if they can't de nested then it seems like the list of rules could get exponentially large.
For example: I want to be able to do something like
as is I believe I would have to flatten such a rule like this to look like the following.
And while that looks better for this simple example if I added another rule to each case i.e.
car.Make == ford
I would potentially have to double the amount of when checks within the non-nested rules. And for each rule chained together the amount of rules that need to be checked could continue to exponentially increase if they cannot be nested.Is this something that is supported/is this a bad use case for this particular rules engine/rule engines in general?