Use Boolean expressions

Many of the decisions you make, involve choices between two options.

The integration engine, and computers in general, work in a similar way. While people can ask questions, the integration engine can check Boolean expressions. A Boolean expression is basically anything that represents one of two values, such as true/false or zero/non zero. The class of such expressions is class B.

The most basic question the integration engine can answer is Are these two values the same or not? Such Boolean expressions are based on two operators, = and <>, as shown in the following examples:

%revision = 19
\customer[%customer_index]\name = "John Doe"
\invoice\date <> \invoice\delivery_date
%tax_rate * 1.05 = %general_tax_base

Testing for equality is done with an equal sign, while testing for difference is done using two angle brackets forming a box. When you use these operators, the integration engine evaluates and compares both sides. When using =, if the values are the same, the result is true while it is false, if the values are different. Operator <> evaluates strictly the opposite: true if different, false if the same.

Testing for difference or sameness operates on any type of values: you can compare numbers (classes B, I and R), dates (class D), strings (class S) or raw-data (class V). Symbolic values absent and null are handled: any value is always different from absent or null, but absent is the same as absent, and null is the same as null.

Do not forget that implicit conversions are always active, you can test "69" (the string) and 69 (the whole number) for sameness. When the integration engine computes such comparison, it first promotes the whole number into a string, then tests for sameness or difference. This can lead to unexpected behaviors: when testing "3.14" against 3.14, promoting 3.14 results in the string ".314e+1" that is really different from "3.14".

Sometimes you need to determine whether something is within a set of values or not. Two operators exist that accept lists of values as right operand: in and out as shown in following examples:

%revision in ( "1.0", "1.1", "1.6", "2.0" )
\customer[1]\name in ( "John Doe", "Jane Smith" )
\invoice\date out ( \invoice\delivery_date, \invoice\sending_date )

The operator in evaluates whether the left operand is the same as one of the values in the right list while out does exactly the opposite. When you use such expressions, the integration engine compares the left side with components in the right side, one after one, until the results is known: if %revision value is "1.1", literals "1.6" and "2.0" is not evaluated.

Determining whether two values are the same or not, is sometimes not enough. You might want to know whether some quantity is greater than that of another, or whether a value is less than some other value. Performing such test is invoked with the > and < operators, respectively. The question they answer is whether the value on their left side is greater (>) or less than (<) the value on their right side.

Sameness and order can be combined in greater than or equals to and less than and equals to operators: >= and <=.

Testing order is quite natural on numbers or dates. For order testing in Boolean expressions, true takes order precedence over false.

Furthermore, you can compare strings which results might appear surprising. Computers are basically unable to manipulate anything other than whole numbers. When you invoke < or > operators with strings, the integration engine is forced to use the series of whole numbers that codes the strings.

The integration engine subtracts the series of the right side string from the one of the left side string. If the value obtained is negative, then left side is considered being less than right side. This is because of the algebraic equivalence: a < b <=> a – b < 0.

If the strings are both, encoded using ASCII derived character sets (ISO8859 and Unicode variations), this preserves lexicographical order for roman letters. String comparison is based on the order that is used in common dictionaries.

Comparing raw-data values (class V) is not supported.

Symbolic values absent and null are not concerned with order: testing order with absent or null results in undefined behavior.

Related Links