CDL Statements

A rule definition written in CDL consists of one or more statements that define the rule's intent.

The two kinds of statements are:

  • Explicit statements

  • Iterator statements

The difference between explicit and iterator statements is in the types of participants involved.

Explicit Statements

Explicit statements express relationships among explicitly identified participants and restrict execution of the rule to those participants and the model containing those participants.

In an explicit statement, you must identify each node and attribute that participates in the rule by specifying its location in the model structure. An explicit statement applies to a specific model, thus all participants of an explicit statement are explicitly stated in the rule definition.

CDL supports several kinds of explicit statements, which are identified by the keywords CONSTRAIN, COMPATIBLE, ADD...TO, and SUBTRACT...FROM.

The following example shows such an explicit statement consisting of a single expression of the logical IMPLIES relation.

CONSTRAIN a IMPLIES b;
CONSTRAIN (a+b) * c > 10 NEGATES d;

Iterator Statements

Iterators are query-like statements that iterate, or repeat, over elements such as constants, model references, or expressions of these. Iterators express relations among participants that are model node elements of a collection, or participants that are identified by their attributes, and allow the rule to be applied to options of option features, or children of option classes, that have the same attributes. Iterators allow you to use the attributes of model nodes to specify the participants of constraints or contributions. This is especially useful for maintaining persistent sets of constraints when the model structure or its attributes change frequently. Iterators can also be used to express relationships between combinations of participants, such as with compatibility rules.

Iterator statements can use local variables that are bound to one or more iterators over collections. This is a way of expressing more than one constraint or contribution in a single implicit form. During compilation, a single iterator statement explodes into one or more constraints or contributions.

The available iterators that make a rule statement an iterator statement are:

  • FOR ALL....IN

  • WHERE

Multiple Iterators in One Statement

The syntax of the FOR ALL clause allows for multiple iterators. The statement can be exploded to a Cartesian product of two or more collections.

The example below produces a Cartesian product as the rule iterates over all the items of the Tint option class in the Glass child model and over all the items of the Color option class in the Frame child model of a Window model. Whenever the Stain user-defined attribute in an item of the Color option class equals the Stain user-defined attribute in an item of the Tint option class, the selected color pushes the corresponding stain to TRUE. So, for example, when &color.userAttrs["Paints_AG.Stain"] and &tint.userAttrs["Paints_AG.Stain"] both equal Clear, selecting the White option causes the Clear option to be selected.

Example: Multiple Iterators in One CONSTRAIN Statement

COMPATIBLE 
&color OF Frame.Color,
&tint OF Glass.Tint
WHERE &color.userAttrs["Paints_AG.Stain"] = &tint.userAttrs["Paints_AG.Stain"];

The difference between this and a compatibility rule is that this code selects participants without over-constraining them, while a compatibility test deselects participants that don't pass the test.

In the following example, the numeric value of feature a contributes to feature b for all the options of a and b when the value of their user-defined attribute UDA2 is equal.

Multiple Iterators in One ADD...TO Statement

ADD &var1 TO &var2
FOR ALL &var1 IN {OptionsOf(a)}, &var2 IN {OptionsOf(b)}
WHERE &var1.userAttrs["UDA2"] = &var2.userAttrs["UDA2"];