Hi Wolfgang, <br><br>Is it the number of instances or how often they are modified that makes the difference? I am just wondering why it is better.<br><br>Best Regards,<br>Michal<br><br><div class="gmail_quote">2009/4/3 David Sinclair <span dir="ltr"><<a href="mailto:dsinclair@chariotsolutions.com">dsinclair@chariotsolutions.com</a>></span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Here you go WolfGang<div class="im"><br><br>rule shoot-3 <br> when<br> $h : Hunter( $target : target)<br>
</div> Animal(this == $target)<div class="im"><br> then<br> $h.shoot( $a );<br> retract( $a );<br>end<br><br>
</div><div class="gmail_quote">2009/4/3 Wolfgang Laun <span dir="ltr"><<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="h5">
Given a working memory containing a large number of rather static facts which are from several subclasses (Ape, Bear, Crocodile,...) of some base class (Animal) and a single fact of class Hunter with a field target of type Animal, the shooting of an animal might be written with a rule like this:<br>
<br>rule shoot-1<br> when<br> ?h : Hunter( ?target : target )<br> ?a : Animal()<br> eval(?target == ?a)<br> then<br> ?h.shoot( ?a );<br> retract( ?a );<br>end<br><br>Avoiding eval (which is said to be inefficient), it could also be written as<br>
<br>rule shoot-2<br>
when<br> ?a: Animal()<br>
?h : Hunter( target == ?a )<br>
then<br>
?h.shoot( ?a );<br>
retract( ?a );<br>
end<br><br>This, however, places the pattern with many instances up front, which is (AFAIK) not so good in a Rete implementation.<br><br>Which one is to be preferred in Drools?<br><br>Ideally, one might want to write <br>
<br>rule shoot-3<br>
when<br>
?h : Hunter( ?target : target )<br>
?a == ?target : Animal() ### not valid DRL<br>
then<br>
?h.shoot( ?a );<br>
retract( ?a );<br>
end<br><br>This avoids eval, has the single instance fact up front, but it isn't available.<br><font color="#888888"><br>-W<br><br><br><br>
</font><br></div></div>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br>