Rules containing calculations and equations
- Last Updated: June 9, 2021
- 3 minute read
- Corticon
- Version 7.2
- Documentation
Rules that contain equations and calculations are no different than any other type of rule. Calculation-containing rules can be expressed in any of the sections of the Rulesheet.
Terminology that will be used throughout this section
In the simple expression A = B, A is the left-hand side (LHS) of the
expression, and B is the right-hand
side (RHS). The equals sign is an operator, and is
included in the Operator Vocabulary in Corticon Studio. But, even such a simple expression has its
complications. For example, does this expression compare the value of A to B in order to take
some action, or does it instead assign the value of B
to A ? In other words, is the equals operator
performing a comparison or an assignment?
This is a common problem in programming languages, where a common solution is to use two
different operators to distinguish between the two meanings: the symbol == might signify a comparison operation, whereas := might signify an assignment.
In Corticon Studio, special
syntax is unnecessary because the Rulesheet helps to clarify the logical intent of the
rules. For example, typing A=B into a Rulesheet's
Condition row (and pressing Enter) automatically causes the
Values set {T,F} to appear in the rule column cell
drop-down lists. This indicates that the rule modeler has written a comparison
expression, and Studio expects a value of true or
false to result from the comparison. A=B, in other words, is treated as a test: is A equal to B?
However, when A=B is entered into an
Action or Nonconditional row (Actions rows in Column 0), it becomes an assignment. In an
assignment, the RHS of the equation is evaluated and its value is assigned to the LHS of
the equation. In this case, the value of B is assigned
to A. As with other actions, you can activate or
deactivate this action for any column in the decision table (numbered columns in the
Rulesheet) by checking the box that automatically appears when the Action's cell is
clicked.
In the Rule Language Guide, the equals operator
(=) is described separately in both its assignment
and comparison contexts.
While this is the expected behavior in the Corticon language, it can cause unexpected results. On input
of a Boolean attribute, if the value of the element is true or 1, Corticon interprets that as
a true Boolean value, otherwise it defaults to a
false Boolean value. Attributes in the input
document are not modified unless the value is changed in the rule; that is, setting a
true Boolean attribute to the value of true does not modify the element.
Entity_1.booleanAttr1 = T ...first set the value
of the attribute to null, and then set it to true:
Entity_1.booleanAttr1 = null
Entity_1.booleanAttr1 = T