company logo

Path extension operand

The path extension operand separates two path elements from each other. Usually, path elements are separated by '.' or '->' (e.g. Person.children). When passing parameters to a path element (Person.income(year)), the parameters are searched in the scope, in which the access path is defined, i.e. "year" could be a variable defined in the same expression, which refers to the access path.

The '->' operator in front of a property indicates, that the subsequent part of the path is searched in a referenced instance. This makes path definitions more transparent and performs a little bit better than using the '.' operator. Nevertheless, the '.' operator works properly in any case.

Since an access path can be used as collection definition but also as execution path, or even as both, the '->' operator in front of a function or expression indicates the execution level for the path (execution operator). An access path should contain only one execution operator. Otherwise, the results may look a little bit strange. The execution operator indicates the operation in the path, until the path is executed when being opened or when being accessed the first time. A path not including an execution operator, can iterate and executes operations according to the iteration requirements.

Executing a path (e.g. Person().children()->MaxIncome()) will iterate automatically over the elements before the execution operation and pass each instance to the execution operation. In this case, the path just contains the result of the last function call. Typically, this is used in connection with templates or the ToFile() operation:

    Person().children().children->ToFile(Path='Console',FieldSeparator=',' LineSeparator=10, HeadLine=true )

When not defining an execution level in the path as in

    bool result = Person().children().children.ToFile(Path='Console',FieldSeparator=',' LineSeparator=10, HeadLine=true );

the expression must iterate over result to execute the ToFile() operation for each instance in the path, e.g. as

    while ( result.Next() ) ;

Using the "@" operator in an access path, will change the scope to the object type defined by the left element. Thus, one may ask for all persons having a child with the same first name using the path Person@children(first_name). Since the @ path operator changes the scope to Person, first_name is searched first in the Person definition. References not found in the Person scope are looked for in the expression scope (local variables) or in the global scope (global variables).

You may also use the @ path operator in a similar way as the "with" operator in MS Visual Basic. Since it is possible defining expressions as path elements, one may define as path as

    Person@{ children + friends; }

Which returns the children and friends for each person. This will work differently, when defining

    Person.{ children + friends; }

In this case, children and friends are searched in the scope of the expression (local variables), in the scope of the calling object for the expression (object variables) or in the global scope.

Definition: 

ext_op := '.' | '@' | '->'