skip to main content
Corticon Studio: Rule Modeling Guide : Rules containing calculations and equations : Datatype compatibility and casting : Datatype of an expression
 

Try Corticon Now
Datatype of an expression
It is important to emphasize that the idea of a data type applies not only to specific attributes in the Vocabulary, but to entire expressions. Our examples above have been simple, and the data types of the LHS or the RHS of an equation simply correspond to the data types of those single attributes. But the data type to which an expression resolves may be a good deal more complicated.
Figure 128. Examples of Expression Datatypes
Again, we will examine each assignment to understand what is happening:
A – The RHS of this equation resolves to an Integer data type because the .dayOfWeek operator extracts the day of the week from a DateTime value (in this case, the value held by attribute date1) and returns it as an Integer between 1 and 7. Since the LHS also has an Integer data type, the assignment operation is valid.
B – The RHS of this equation resolves to an Integer because the .size operator counts the number of characters in a String (in this case the String held by attribute string1) and returns this value as an Integer. Since the LHS also has an Integer data type, the assignment operation is valid.
C – The RHS of this equation resolves to a Boolean because the ->isEmpty collection operator examines a collection (in this case the collection of Entity2 children associated with parent Entity1, represented by collection alias e2) and returns true if the collection is empty (has no elements) or false if it isn't. Since the LHS also has a Boolean data type, the assignment operation is valid.
D – The RHS of this equation resolves to a Boolean because the ->exists collection operator examines a collection (in this case, e2 again) and returns true if the expression in parentheses is satisfied at least once, and false if it isn't. Since the LHS also has a Boolean data type, the assignment operation is valid.
E – the RHS of this equation resolves to an Integer because the ->sum collection operator adds up the values of all occurrences of an attribute (in this case, integer2) in a collection (in this case, e2 again ). Since the LHS has a Decimal data type, the assignment operation is valid. This is the lone case where type casting occurs automatically.
Note: The .dayOfWeek operator and others used in these examples are described fully in the Rule Language Guide