[rules-users] what's wrong with this rule?...

Edson Tirelli tirelli at post.com
Tue Mar 6 17:23:54 EST 2007


   Vlad,

   Yes, we do need to write all the documentation. We simply couldn't so 
far...

   Thanks for letting us know about the "return" keyword. Not sure if 
someone already fixed the Wiki, but seems it is correct now.

    Regarding the eval(), it is pure java code, so I guess you are using 
java 5 or 6 and it is auto-unboxing the integer for you... but better is 
to avoid it completelly.

    Regarding doing Integer( intValue > 4 ), just remembet that any 
method that takes no parameters and whose return type is different than 
"void" can be used as a constraint. So you can write things like:

Double( intValue > 10 )
List( size < 5 )
Map( empty == true )

     etc

    []s
    Edson


Olenin, Vladimir (MOH) wrote:

>Edson,
>
>Thanks for the tip - you are right - 'return' keyword should not be used -
>got to this one by trial & error just before I saw your reply :). The
>problem is that the only 'public' docs available on the new functionality
>(Wiki 3.1 release notes:
>http://wiki.jboss.org/wiki/Wiki.jsp?page=3.1M1ReleaseNotes) gives the
>example of 'accumulate' keyword where 'return' keyword IS used in the
>'result' section! So, I guess this needs to be updated?..
>
>Interestingly, "eval ($count < 4)" DOES work correctly and as expected! So,
>I guess that's an extra feature? :)
>
>Thanks for the example on how to avoid eval altogether - already tried it
>and it works like a charm! Nice functionality! Would it be worth it to
>include this in Wiki?
>
>Thanks,
>
>Vlad
> 
>
>-----Original Message-----
>From: rules-users-bounces at lists.jboss.org
>[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Edson Tirelli
>Sent: 06 March 2007 16:19
>To: Rules Users List
>Subject: Re: [rules-users] what's wrong with this rule?...
>
>
>Vlad,
>
>You should not use the "return" keyword and the ";" inside the result 
>block as it is implicit. Also, remember that anything inside eval() is 
>pure java code, so you cant do $count < 4 if $count is an Integer object.
>Finally, try to always avoid eval() when writing rules.
>
>Try something like:
>
>*rule* "FG.23C"
>
>*when*
>
>*exists*
>
>Record( $psc : psc == "323",
>
>pa == "7[0-9]*",
>
>sa == "F39040"
>
>|== "F38010"
>
>|== "F38090" )
>
>$count : Integer( intValue < 4 ) *from* *accumulate *(
>
>Record( psc == "323",
>
>pa *matches* "8[0-9]995",
>
>sa *matches* "F390[4-8][2-5]" ),
>
>init ( *int* count = 0; ),
>
>action( count += count; ),
>
>result( *new* Integer(count) )
>
>)
>
>*then*
>
>System.out.println( "rule FC.23C has failed" );
>
>System.out.println();
>
>*end*
>
>**
>Please, let me know if it works.
>
>[]s
>Edson
>
>Olenin, Vladimir (MOH) wrote:
>
>  
>
>>Hi,
>>
>>I have the following rule:
>>
>>*rule* "FG.23C"
>>
>>*when*
>>
>>*exists*
>>
>>Record( $psc : psc == "323",
>>
>>pa == "7[0-9]*",
>>
>>sa == "F39040"
>>
>>|== "F38010"
>>
>>|== "F38090" )
>>
>>$count : Integer() *from* *accumulate *(
>>
>>Record( psc == "323",
>>
>>pa *matches* "8[0-9]995",
>>
>>sa *matches* "F390[4-8][2-5]" ),
>>
>>init ( *int* count = 0; ),
>>
>>action( count += count; ),
>>
>>result( *return* *new* Integer(count); )
>>
>>)
>>
>>*eval* ($count < 4 )
>>
>>*then*
>>
>>System.out.println( "rule FC.23C has failed" );
>>
>>System.out.println();
>>
>>*end*
>>
>>* *
>>
>>And for some reason I can't compile correctly: I'm getting the 
>>following error:
>>
>>org.drools.rule.InvalidRulePackage: Rule Compilation error This method 
>>must return a result of type Integer Syntax error on token "(", ; 
>>expected Syntax error on token ")", delete this token
>>
>>at org.drools.rule.Package.checkValidity(_Package.java:367_)
>>
>>at 
>>org.drools.common.AbstractRuleBase.addPackage(_AbstractRuleBase.java:244_)
>>
>>at moh.ohfs.rules.RulesTest.readRule(_RulesTest.java:70_)
>>
>>at moh.ohfs.rules.RulesTest.main(_RulesTest.java:22_)
>>
>>All brackets seem to be matching.... This happens on 3.1M build.
>>
>>Thanks,
>>
>>Vlad
>>
>>------------------------------------------------------------------------
>>
>>_______________________________________________
>>rules-users mailing list
>>rules-users at lists.jboss.org
>>https://lists.jboss.org/mailman/listinfo/rules-users
>> 
>>
>>    
>>
>
>
>  
>


-- 
 Edson Tirelli
 Software Engineer - JBoss Rules Core Developer
 Office: +55 11 3124-6000
 Mobile: +55 11 9218-4151
 JBoss, a division of Red Hat @ www.jboss.com





More information about the rules-users mailing list