| Reference > Rule Languages > ILOG Rule Language > IRL Keywords > exists |
exists |
PREVIOUS NEXT |
A statement that tests if a class condition is true. This keyword is used in rule conditions.
exists condition;
The exists statement is used in the condition part of a rule. It may be applied to a simple condition, an in statement, or a from statement. The exists statement tests whether the condition is true. An exists statement returns true for a simple condition if the working memory contains at least one object that can match the condition. An exists statement returns true with an in or from statement when the in or from statement returns true. The contrary of exists is not (avoid not exists).
An exists statement cannot be bound to an external variable. The exists statement returns true when any object in the working memory matches the condition. This condition does not discriminate which object was matched. Hence it is illegal to bind this condition to a variable.
Any variable bound within the exists statement is local to the statement. The variable cannot be referred to in the remainder of the rule.
The special variable ?this may be used within the exists statement to designate the current working memory object being tested.
rule GeneralCustomerRequest {
when {
CustomerRequest(?item:request);
exists Item(?this == ?item);
}
then {
System.out.println(?item + " are in stock.");
}
};
The GeneralCustomerRequest rule uses the exists statement to verify that an item requested by a customer exists. The exists statement returns true when a single instance of the object is found, which is faster than providing all the items that match the customer's request.
In the first condition, CustomerRequest, the variable ?item is matched with the field request. In the exists statement, the Item object is represented by the variable ?this and is tested whether it is equal to the variable ?item. The action part is executed if an Item object is matched, printing that the item(s) "are in stock."
| Copyright © 1987-2008 ILOG S.A. All rights reserved. Legal terms. Documentation homepage. | PREVIOUS NEXT |