Reference > Rule Languages > ILOG Rule Language > IRL Keywords > in

Summary

A statement that supports relations between object values. This keyword is used in rule conditions.

Syntax

condition in expression; 

Description

The in statement is used in the condition part of a rule to express the relations between values. It is used to test if the value of the condition is a member of the set of values returned by the in expression. The expression may be an array, a java.util.Vector, a java.util.Enumeration, or a java.util.Collection.

The in statement allows you to retrieve not only objects in the working memory but also objects that are linked to other objects by fields or by method invocations.

In combination with the collect statement, the in statement allows you to express logical statements such as all, at least, and none (see examples below).

The in statement provides performance advantages since the pattern matching is done on a reduced number of objects and not on all the objects in the working memory.

Examples

?c: Customer();
?d: Item() in ?c.boughtItems();

The above code will retrieve the items bought by the customer even if they are not inserted in the working memory. The variable ?d will return the items bought. The method boughtItems() may return a user-defined array, a java.util.Vector, or a java.util.Enumeration.

?c: Customer();
collect Item(price > 10) in ?c.boughtItems() where (size() > 0);

The in statement is used within a collect statement to retrieve all the items bought by the customer with a price larger than 10. The where part tests that the collection has at least one element, using the method size().

?c: Customer();
collect Item(price > 10) in ?c.boughtItems() where
             (size() == ?c.boughtItems().length() );

This is similar to the previous example except that the where part now tests that all the items bought had a price larger than 10. This is done by testing the equality of the results from the methods size() and length().

See Also

collect, exists, from, not