[rules-users] Is "emptieness" supported in Drools 5 (LHS)

Macon Pegram mpegram3rd at gmail.com
Wed Aug 19 09:52:03 EDT 2009


Edson,

Thanks for clarifying this.  I appreciate it.

Macon

2009/8/19 Edson Tirelli <tirelli at post.com>

>
>    Sometimes this is indeed not clear, so I will try to explain here.
> Drools uses MVEL to resolve some expressions and semantic code. Although we
> would like to make it 100% compatible and enable it to use mvel everywhere,
> that is easier said than done (but we do have someone working on that).
>
>    Anytime you want to force Drools to fallback into MVEL (or java, as the
> other supported dialect) you need to place your code inside an eval(). For
> some well known situations, Drools does this automatically, but that is not
> the case with empty.
>
>    For now, in your case, you could either do:
>
> MyGrabBag( someMap != null, someMap.empty == true )
>
>    Or if you are using mvel as your rule dialect:
>
> MyGrabBag( eval( someMap == empty ) )
>
>    []s
>    Edson
>
>
> 2009/8/18 Pegram, Macon <zmpegram at choosehmc.com>
>
>>  According to MVEL they’ve added a convenience for checking the
>> “emptiness” of a value (see: http://mvel.codehaus.org/Value+Tests )
>>
>>
>>
>> In MVEL you’d simply write:  myMap == empty
>>
>>
>>
>> This seemed like a MUCH cleaner way to write some of the LHS of the rules,
>> so I thought I’d try it out.
>>
>>
>>
>> Given the following rule:
>>
>> *rule* "Check Empties - Original"
>>
>>     *when         *
>>
>>         $grabBag : MyGrabBag(someMap != null)
>>
>>         *eval* ($grabBag.getSomeMap().size() == 0)
>>
>>     *then*
>>
>> *end*
>>
>> * *
>>
>> This could be rewritten:
>>
>> * *
>>
>> *rule* "Check Empties - Simple"
>>
>>     *when         *
>>
>>         MyGrabBag(someMap == *empty*)
>>
>>     *then*
>>
>> *end*
>>
>>
>>
>> The IDE (Eclipse 3.4.2 w/ Drools plugin) seems to recognize “empty”  is a
>> keyword (it makes it bold), but the drools compiler in the IDE  reports:
>> BuildError: Unable to create restriction '[VariableRestriction: == empty
>> ]' for field 'someMap' in the rule 'Check Empties - Simple'
>>
>> BuildError: Unable to return Declaration for identifier 'empty'
>>
>>
>>
>> Am I assuming incorrectly that the LHS is fully MVEL compliant?
>>
>>
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>
>
> --
>  Edson Tirelli
>  JBoss Drools Core Development
>  JBoss by Red Hat @ www.jboss.com
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20090819/0a090d74/attachment.html 


More information about the rules-users mailing list