[] operator
The [] operator creates a property that returns an object from a structure.
Syntax
expr[n]
Where [ and ] are ordinary square brackets.
Description
The [] operator creates a property that takes a structure as input and returns the structure object at the position given by n.
Parameters
-
exprAn expression whose value must be a structure.
-
nThe position of the object within the structure. A positive integer literal: it must be written as a constant, not computed from an expression. Numbering is 1-based, and the value must be within the range
[1..N], whereNis the number of objects in the structure.
Examples
CLASS Letter;
attachment1 = DATA FILE (Letter);
attachment2 = DATA FILE (Letter);
letterAttachments (Letter l) = STRUCT(attachment1(l), attachment2(l));
secondAttachment(Letter l) = letterAttachments(l)[2]; // returns attachment2