Table of Contents

Aggregates

Generator expressions provide a convenient and efficient means to yield multiple values. Their counterpart are aggregate expressions which take multiple values in succession as input and produce a single value as result, e. g., the sum of all values. The XL programming language defines a single built-in aggregating operator (the containment operator) and a mechanism for aggregate methods.

Containment Operator

The containment operator a in b aggregates the logical or of a == b.

Typical examples are a in (1 : 3) which has true as result if and only if a equals 1, 2 or 3, or a in n.children() which tests whether a node a is contained in the sequence of values returned by the generator method n.children(). The containment operator terminates the evaluation of the generator expression once it knows the final result, i. e., if a == b has been true for some pair a, b.

The containment operator, like instanceof, does not follow the general pattern that only symbols and no keywords are used for operators.

Aggregate Methods

Like filter methods, aggregate methods receive a sequence of values as input. However, their result is a single value.

When used in the code, the first two argument of the method are “combined”. The first argument given has to be an Aggregate of the Type of the second argument

public static boolean checkVal (Aggregate a, Object x) { ... }
Object[] myarray = new Object[] { ... };
boolean result = checkVal( myarray ); // The method takes two arguments, but only one is given

→ Read more...