|
Related pages:
Expressions can be used almost anywhere in Blueriq and are an essential part of modeling. You can view expressions in several ways:
Expressions can be used for an endless number of purposes in Blueriq. Here are some examples:
In Blueriq Encore it is possible to use expressions in all fields accompanied by an expression icon:
Clicking on this icon will open the expression editor in a dialog, giving you the space and focus to type your expression.
Expressions can be very basic or very complex. These are all examples of expressions:
Tip: Use brackets when expressions get more complex to clearly indicate which parts belong together. |
Each expression returns a value with a particular type. Please see the page for Attribute for an overview of types. Note that an expression can also return Expression, collections of Expression and collections of other types!
See the Expression page for information on referring to Attribute and Relation of instances.
See the Expression & function reference for a complete list of functions and operators that can be used in expressions.
It is possible to save expressions that occur multiple times for reuse. See the Reusable expression page for more information.
In complicated expressions, you can use local variables to split the expression up into several smaller statements. An example, finding everyone with the same birthday as Bob.
Without local variables:
COLLECT Person FROM ALL Person WHERE (DAY (Person.BirthDate) = (COLLECT DAY (Person.BirthDate) FROM ALL Person WHERE (Person.Name = "Bob")) AND MONTH (Person.BirthDate) = (COLLECT DAY (Person.BirthDate) FROM ALL Person WHERE (Person.Name = "Bob")) |
With local variables:
BobsBirthDate := COLLECT Person.BirthDate FROM ALL Person WHERE (Person.Name = "Bob"); BobsBirthDay := DAY (BobsBirthDate); BobsBirthMonth := MONTH (BobsBirthDate); COLLECT Person FROM ALL Person WHERE (DAY (Person.BirthDate) = BobsBirthDay AND MONTH (Person.BirthDate) = BobsBirthMonth) |
Local variables follow this syntax:
VariableName1 := TRUE; VariableName2 := FALSE; VariableName1 OR VariableName2 |
Local variables cannot be referenced outside the expression they were defined in! |
Even relatively simple expressions can benefit from comments that explain what (a part of) a particular expression does.
/* This is a comment explaining the local variable */ LocalVariable1 := Entity.Value; // This is a comment explaining the expression below Entity.Value > 0 |
Blueriq stops evaluating expressions as soon as the result is known. This means a second argument is executed or evaluated only if the first argument does not suffice to determine the value of the expression
Take this simple example: Person.Gender = "Female" AND Person.IsWorking.
If the person in question is male, the condition Person.IsWorking will not be checked. This means that underlying Justification will not be triggered.
For best performance, put the "cheapest" (least resource intensive) conditions on the left, and the "most expensive" on the right. |