Spec-Zone .ru
спецификации, руководства, описания, API

postfixExpression

Figure 6.29. postfixExpression

postfixExpression

Member Access

Access a member (variable or function) of a class instance.

Figure 6.30. postfixExpression [Member Access clause]

postfixExpression [Member Access clause]

This example shows member access using a dot of both a variable (aPair.good) and a instance function (aPair.topsy()):

class Pair {
   var good : String;
   var bad : String;
   function topsy() {
      def tmp = good;
      good = bad;
      bad = tmp;
   }
}
def aPair = Pair {
   good: 'Sunflower Sprouts'
   bad: 'Lard'
}
println( aPair.good );
aPair.topsy();
println( aPair.good );

It will print:

Sunflower Sprouts 
Lard

Function Invocation

Function invocation, also known as function call, is how functions are, well..., called.

Figure 6.31. postfixExpression [Function Invocation clause]

postfixExpression [Function Invocation clause]

Figure 6.32. 


This is an example of calling a script function, see the Member Access section for an example of calling an instance function:

function squared(x : Number) : Number { x * x }
println( squared(14,2) );

Sequence Select

A sequence select expression evaluates to a new sequence containing selected elements of another sequence.

Figure 6.33. postfixExpression [Sequence Select clause]

postfixExpression [Sequence Select clause]

Elements are included in the resulting sequence if the Boolean valueExpression evaluates to true. The name provides a name for each element for use in the valueExpression. For example:

def seq = [1..100];
def selected = seq[x | (x*x) < 20];
println( selected );

The selected elements of seq are those whose square is less than 20. So the following is printed:

[ 1, 2, 3, 4 ]

Note that this selection could also have been done with the equivalent for-expression:

def selected = for (x in seq where (x*x) < 20) x;

Sequence Indexing

A sequence indexing expression accesses a single element of a sequence at the supplied index. If no element exists at that index, the sequence indexing expression will evaluate to the default value for the element specifier of the sequence.

Figure 6.34. postfixExpression [Index clause]

postfixExpression [Index clause]

For example:

def seq = [100..105];
println( seq[0] );
println( seq[3] );
println( seq[22] );
println( seq[-1] );

Here the element specifier of seq is Integer, so the following is printed -- since zero is the default value of Integer:

100 
103 
0 
0

The type of a sequence indexing expression is that of the indexed sequence's element specifier (the element type).

Sequence Slice

A sequence slice expression evaluates to a sequence which is a portion of another sequence. The elements which make up the portion are specified by a range of indices.

Figure 6.35. postfixExpression [Slice clause]

postfixExpression [Slice clause]

The two valueExpressions give the beginning and ending of the range. The beginning is always inclusive, the ending of the range is inclusive unless the less-than sign is used. The ending valueExpression is optional, and if absent, the ending of the range is the last index of the sequence. For example:

def usprez = ['Washington', 'Adams', 'Jefferson', 'Madison', 'Monroe'];
println( usprez[1..3] );
println( usprez[1..<3] );
println( usprez[3..] );
println( usprez[3..<] );

Will print to the console:

[ Adams, Jefferson, Madison ]
[ Adams, Jefferson ] 
[ Madison, Monroe ] 
[ Madison ]

The type of a sequence slice expression is the type of the sequence to which the slice clause is applied.