You are viewing the documentation for Blueriq 17. Documentation for other versions is available in our documentation directory.

What is it for?

The expression is the basis for all Logic in Blueriq.

Introduction

Expressions can be used almost anywhere in Blueriq and are an essential part of modeling. You can view expressions in several ways:

  • A kind of formula
  • A sentence, but then in code
  • You can put all kinds of information into expressions and get a value out
  • Expressions can contain other expressions

Uses

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.

Examples

Expressions can be very basic or very complex. These are all examples of expressions:

  • 1
  • "Hello"
  • TRUE
  • ?
  • Child.Name
  • Customer.IsWorking
  • Customer.HoursWorked > 0
  • Customer.FirstName + " " + Customer.LastName
  • Customer.HasChildren
  • ALL Child
  • COLLECT Child.Age FROM ALL Child
  • [6 , 4 , 1 , 10]
  • SUM(COLLECT Child.Age FROM ALL Child WHERE (Child.Gender = "Male"))
  • Customer.IsWorking OR Customer.IsStudying
  • (Customer.IsWorking OR Customer.IsStudying) AND (NOT Customer.HasPartner OR Partner.IsWorking OR Partner.IsStudying)

Tip: Use brackets when expressions get more complex to clearly indicate which parts belong together.

Typing

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!

What can I use in an expression?

Instances

See the Expression page for information on referring to Attribute and Relation of instances.

Reference guide

See the Expression & function reference for a complete list of functions and operators that can be used in expressions.

Reusable expressions

It is possible to save expressions that occur multiple times for reuse. See the Reusable expression page for more information.

Local variables

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!

Comments

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

Minimal evaluation

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.

  • No labels