Instance selection

Instances can be selected directly from a specified class or by traversing relationships from some instance to a destination class. In both cases criteria may be specified to select a subset of a class population.

To obtain the entire population of a class, just assign the class to an instance set variable using the * select all operator.

airports ..= Airport(*)  // assigns all instances of Airport

To get a subset, specify criteria.

airports in my country ..= Airport( Country : my country )

In the context of an instance selection, the : symbol reads as “is” or “equals” and the , symbol reads as “and”. You can always substitute == and the and keyword, but these lead to clutter especially when multiple attributes are involved in a selection.

To improve readability and, or, and not are keywords in Scrall. They are short and quick to type. This also avoids confusion with current or future uses of symbols like !, &, and |. The odds of those keywords being used accidentally in a variable name should be quite small.

To get a particular instance use an identifier and assign to an instance set variable:

origin airport .= Airport( Code : origin code )

Selection criteria can use the usual comparison operators if they are defined for the attributes involved in the comparison. Typically, these are >, >=, <, data-preserve-html-node="true" <=, data-preserve-html-node="true" =, !=

high aircraft ..= Aircraft( Altitude > high alt )
high and fast aircraft ..= Aircraft( Altitude > high alt and Airspeed > min fast speed )

Min and max comparisons use ^+ and ^- unary operators. They can be applied only to attributes with data types that support comparison operations.

fastest aircraft ..= Aircraft( ^+Airspeed )
slowest aircraft ..= Aircraft ^-Airspeed )
allbut fastest aircraft ..= Aircraft( not ^+Airspeed )

Multiple ordering comparisons may be used and applied in the indicated order:

next tasks ..= Task( ^+Priority, ^-Time submitted )

In all of the above cases, multiple instances may be selected. There could be many Tasks at the same Priority, submitted at the same time, for example. But it is possible to select an arbitrary instance among those selected:

next task .=. Task( ^+Priority, ^-Time submitted )

In this case, zero or one instance will be selected, but the zero case would only occur when the cardinality of Task is also zero.

Methods in criteria

A method that returns a value may be used just like an attribute in a selection expression.

If a class method returns a scalar value of a type that supports comparison operations, the ^+ and ^- unary max min can be applied. Here’s an example where the lowest duration returned by a method is used as the selection criteria.

cabin to call .=. /R4/Shaft/R2/Cabin( ^-Estimated delay( Destination: Floor ) )

Traversal from the local instance across two associations leads to the Cabin class. Multiple instances may be associated, so the Cabin.Estimated delay( Destination ) method is invoked on each instance and the one returning the least value is assigned to the instance set variable.

True and false instance sets

The empty set corresponds to false while one or more instances in a set corresponds to true.