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

expression

At the top level of expression syntax are the expressions that stand alone and, with the exception of valueExpression, have no value (are of Void type).

Figure 6.1. expression

expression

insert

The insert expression is used to insert a value (which may be a sequence) into a sequence.

Figure 6.2. insert

insert

Figure 6.3. indexedSequenceForInsert

indexedSequenceForInsert

insert-into inserts into the sequence at the end. The other forms allow you to specify where in the sequence the value should be inserted by using an indexed expression. insert-before inserts before the indexed element; insert-after inserts after the indexed element. For example:

var names = ['Evelyn', 'Will'];
insert 'Marsha' into names;
println(names);
insert ['Ron', 'Melissa'] before names[1];
println(names);
insert 'Daz' after names[3];
println(names);

Will print:

[ Evelyn, Will, Marsha ]
[ Evelyn, Ron, Melissa, Will, Marsha ]
[ Evelyn, Ron, Melissa, Will, Daz, Marsha ]

Note that inserting a sequence inserts the elements of the sequence -- sequences are never nested.

Inserting before or after a negative index inserts at the beginning of the sequence. Inserting before or after an index beyond the end of the sequence inserts at the end of the sequence. Though neither of these cases is implemented in V1.0 of the language.

An insert expression has no value, it is of Void type.

delete

The delete expression is used to delete an element or elements from a sequence.

Figure 6.4. delete

delete

Delete has four forms:

Table 6.1. Form of Delete

delete sequence[index] Delete from sequence the element at index. If there is no element at that index, ignore the delete.
delete sequence[begin..end] Delete from sequence the elements from indicies begin to end inclusive. If there is no element at some of these indicies, those indicies are ignored. Note that, more generally, this allows full slice syntax. See slices.
delete value from sequence Delete all occurrances of the value from the sequence. If there are no occurrances of the value, no action is taken.
delete sequence Delete all elements from the sequence -- but not the sequence itself.

For example:

var names = [ 'Donna', 'Barb', 'Ron', 'Melissa', 'Will', 'Daz', 'Jim' ] ;
println(names);
delete 'Will' from names;
println(names);
delete names[1..3];
println(names);
delete names[0];
println(names);
delete names;
println(names);

Will print:

[ Donna, Barb, Ron, Melissa, Will, Daz, Jim ]
[ Donna, Barb, Ron, Melissa, Daz, Jim ]
[ Donna, Daz, Jim ]
[ Daz, Jim ]
[ ]

A delete expression has no value, it is of Void type.

while

The while expression evaluates its body (the expression after the close-parenthesis) repeatedly as long as the Boolean condition (the valueExpression) is true. Basically the same as a while-loop in most languages.

Figure 6.5. while

while

A while expression has no value, it is of Void type.

break

Evaluating a break causes the loop in which it is lexically contained to terminate. Where a loop is either a while or for-expression.

Figure 6.6. break

break

A break always completes abruptly and thus has no value.

continue

Evaluating a continue causes the loop it is lexically contained to immediately complete the iteration currently executing and attempt the next iteration. Where a loop is either a while or for-expression.

Figure 6.7. continue

continue

A continue always completes abruptly and thus has no value.

throw

A throw expression causes an Exception to be thrown. See the Error Handling chapter.

Figure 6.8. throw

throw

A throw expression always completes abruptly and thus has no value.

return

A return expression causes return from a function, optionally with the value of the function.

Figure 6.9. return

return

try

Exceptions are caught by enclosing expressions in try blocks.

Figure 6.10. try

try

Figure 6.11. catchClause

catchClause

Figure 6.12. finallyClause

finallyClause

The try block is executed until either an exception is thrown or it finishes successfully. If an exception is thrown, each catchClause is examined in turn, to see whether the type of the exception object matches the type declared in the formalParameter to the catchClause. If a match is found, the block of that catchClause is executed; with the formalParameter set to the exception object. No other catchClause will be executed. If no matching catchClause is found, the exception propagates out of the try.

The try expression may have a finallyClause. A finallyClause provides a mechanism for executing a section of code whether or not an exception is thrown. Usuall the finallyClause is used to clean up or release resources.

Neither a catchClause or finallyClause is required, but one must be present.

A try expression has no value, it is of Void type.