[rules-dev] IRC: interesting topic: use of lists using "from" in LHS and iterated over in RHS

Mark Proctor mproctor at codehaus.org
Mon Aug 9 07:14:54 EDT 2010


  On 06/08/2010 16:04, Anstis, Michael (M.) wrote:
>
> HI,
>
> There was an interesting discussion today on IRC; a user "jochen" 
> reported NPEs when trying to iterate lists in the RHS constructed in 
> the LHS using "from collect".
>
> I was wondering how Drools handles lists constructed in the LHS; if 
> the list contained 5 elements but another rule retracted one of those 
> elements would the list available in the RHS contain 4 or 5 elements?
>
> Here's a simplification of what was posted at 
> _http://pastebin.com/yKGSxFkA_
>
> Rule 1
> when
> $cheese : ArrayList() from collect(CheeseFact());
> then
> for(int i=0; i<$cheese.size(); i++) {
> //Something useful...
> }
> end
>
> What if there was another rule that did something like this:-
>
> Rule 2
> When
> $cf : CheeseFact(type == "chedder")
> Then
> retract($cf);
> end
>
Each time this "rule 2" fires and retracts a CheeseFact that was in 
$cheese from rule1, the $cheese list will be reduced by one. So there 
should be no null pointers here.

Mark
>
> What would be the list Rule 1 iterates?
>
> I'd assume since I believe activation execution to be serial it would 
> depend on the agenda's conflict resolution strategy or rule salience?
>
> What would be the learned opinion?
>
> With kind regards,
>
> Mike
>
>
> _______________________________________________
> rules-dev mailing list
> rules-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-dev/attachments/20100809/88ef1f46/attachment-0001.html 


More information about the rules-dev mailing list