[rules-users] Forall Conditional Element

Edson Tirelli tirelli at post.com
Tue Jan 16 16:31:20 EST 2007


   All,

   JBRULES-218: http://jira.jboss.com/jira/browse/JBRULES-218 adding 
support to the "forall" conditional element is commited into trunk.

   You all are welcome to try. Documentation is still pending but 
follows a quick walkthrough:

Syntax:

forall( BasePattern([constraints]*)[,] [AdditionalPattern([constraints]) 
[,]]* )

Example:

forall( Person( $likes: likes ),
         Cheese( type == $likes ) )

The above statement can be translated to: "for all Person facts, there 
must be a Cheese fact whose type is the one the person likes".
In other words, a forall is translated to:

not( BasePattern(...) and not( AdditionalPattern(...) and 
AdditionalPattern(...) ... ) )

So you can make sure that all charges to a credit card have 
corresponding charge type and issueing store:

forall( Charge( $type: type, $issuer: issuer ),
         ChargeType( type == $type ),
         Store( name == $issuer ) )

This is equivalent to (but much cleaner to write):

not( Charge( $type: type, $issuer: issuer ) and
      not( ChargeType( type == $type ) and
             Store( name == $issuer ) ) )

   Let me know if you have any question or find any problem.

   Thanks,

   []s
   Edson 

 -- 
 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