Declarative Objectivity (DO) Language : Operator Expressions : Selection Operators
Selection Operators
Selection operators return the values of reachable attributes or collection elements.  
Operator
Description
Usage
First Operand
(op1)
Second Operand
(op2)
Third Operand
(op2)
Result Type
See Also
.
 
Dot operator.
Returns the value of an attribute of an embedded or referenced object
op1.op2
Embedded object,
Reference
Any type
Same as op2 1
.
Dot operator.
Returns a sequence of values obtained from a collection or sequence of embedded or referenced objects
op1.op2
Collection or sequence of embedded objects or references
Any type
List or sequence with element type same as op2 1, 2, 3
[]
Subscript operator with index subscript.
Returns an element at an index location
op1[op2]
List
Integer (positive or negative)
Element type of op1 1, 4
[]
Subscript operator with range subscript.
Returns an element at a range of index locations
op1[op2:op3]
List
Integer (positive or negative)
Integer (positive or negative)
Sequence with element type same as op1 1, 5
[]
Subscript operator with predicate subscript.
Returns elements that match the expression op2
op1[op2]
Collection or sequence of embedded objects or references
Boolean
Sequence with element type same as op1 1
1. Returns null if op1 is a null value.
2. If op1 is a collection of embedded objects, any null object in the collection is excluded from evaluation.
3. If op1 is a list, the result type is a list. If op1 is any other kind of collection, the result is a sequence.
4. Returns null if the specified index is out of bounds.
5. Automatically adjusts the range if either op2 or op3 is out of bounds.
Quick Look 
Find the vehicle associated with the rental contract whose tracking number is 782, and return the vehicle’s stall number and airport location:
FROM Vehicle WHERE currentRental.trackingNumber == 782 RETURN atStall.number, atStall.location.airportCode; 
Update a particular customer by clearing the first rental contract from the list of rental contracts:
UPDATE Customer WHERE lastName == 'Mertz' CLEAR rentals[0];
Return the first 5 service records for a particular vehicle:
FROM Vehicle WHERE license == 'ABC1997' RETURN servRecs[0:5];
From the rental company’s list of vehicle models, select just the models with the specified seating capacity and return their names:
FROM RentalCompany RETURN models[seatingCapacity > 6].modelName;
Return the number of available vehicles in the rental company’s collection of vehicles:
FROM RentalCompany RETURN COUNT(vehicles[available == true]);
Discussion 
For general information about operator formats, operands, and precedence, see About Operator Expressions.
You use the subscript operator in Collection-Element Expressions. You can use combinations of the dot operator and the subscript operator in Expressions for Reachable Values.
The dot operator is named for its token, which is a period or “dot”.
Dot Operator Returning a Single Value
You can use a dot operator expression to select and return a single value. Within such an expression:
The first operand (typically an attribute expression) evaluates to an embedded object or a referenced object.
The second operand designates an attribute of that object.
The result is the value of the designated attribute.
Example. In the WHERE clause, the currentRental expression evaluates to the RentalContract object referenced by a Vehicle. The dot operator then returns the value of the RentalContract’s trackingNumber attribute.
FROM Vehicle WHERE currentRental.trackingNumber == 782 RETURN atStall.number; 
If a dot-operator expression returns an embedded object or an object reference, you can use it as the first operand of another dot-operator expression.
Example. In the RETURN clause, the atStall.location expression returns a referenced Location object. The subsequent dot operator then returns the value of the Location’s airportCode attribute:
FROM Vehicle WHERE currentRental.trackingNumber == 782 RETURN atStall.location.airportCode; 
For further examples, see Attribute Value of a Referenced Object, Attribute Value of an Embedded Object, and Elements of an Indirectly Held Collection.
Dot Operator Returning Multiple Values
You can use a dot operator expression to select and return a sequence of values. Within such an expression:
The first operand (typically a collection-element expression) evaluates to a collection or sequence of embedded or referenced objects.
The second operand designates an attribute of the objects in that collection or sequence.
The result is a sequence of attribute values, one from each object.
Example. In the RETURN clause, the vehicles expression evaluates to the collection of Vehicle objects held by the RentalCompany. The dot operator then returns a sequence consisting of the license attribute value from each Vehicle in the collection.
FROM RentalCompany RETURN vehicles.license;
The resulting sequence may be nested and combined with other operators.
Example. The expression in the WHERE clause finds a RentalCompany that has a vehicle with a particular license:
FROM RentalCompany WHERE vehicles.license ANY_EQUAL 'L321X93' RETURN *;
For further examples, see Values from Collected Objects.
Subscript Operator
You use the subscript operator to select and return one or more element values from the collection specified by the first operand. You can specify different types of subscripts for the remaining operand(s):
 
Subscript Type
Subscript Operator Action
Quick Example
For Details
Index subscript
Returns the element at the specified index n, where n is an integer. The collection must be a list.
rentals[0]
rentals[-1]
Range subscript
Returns a sequence consisting of the elements from the first specified index m up to the second specified index n. The nth element is not included. The collection must be a list.
servRecs[0:5]
servRecs[-3:-1]
Predicate subscript
Returns a sequence consisting of the elements that return true when tested against the specified predicate expression. The collection may be a list, set, or map.
vehicles[available == true]