Hi All,
Just wanted to share with you an easy mistake. This is done running
Drools 5.5.0.Final.
Imagine a fact
Cheese (
creationTick : double
preservationTicks : double
)
Then the following does not do what you expect:
rule "dump old cheese"
when
$c : Cheese( $sbd : creationTick +
preservationTicks )
CurrentTime( tick >= $sbd )
then
System.out.println("
we have to
dump "+$c);
end
You would expect that $c is dumped when current time has passed
creationTick + preservationTicks. But no. The variable $sbd is bound
to creationTick before the preservationTicks are added!! I
must say that I do not quite understand how ($sbd : creationTick) +
preservationTicks resolves to "true" to make the premise succeed...
Maybe because it is != 0?
I found that it should be:
rule "dump old cheese"
when
$c : Cheese( $sbd : (creationTick + preservationTicks) )
CurrentTime( tick >= $sbd )
then
System.out.println("we have to dump "+$c);
end
This makes sense. Now $sbd is bound to the result of the addition.
But it is an easy trap!!
Regards,
Willem