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

assignmentExpression

An assignmentExpression assigns the value of the right-hand-side (valueExpression) to the variable, sequence element, or sequence slice referenced on the left-hand-side.

Figure 6.18. assignmentExpression

assignmentExpression

This example demonstrates sequence element, or sequence slice assignment:

var food = ['cheese', 'soda', 'fries', 'cupcake'];
println( food );
food[2] = 'eggplant';
println( food );
food[4] = 'measles';   1
println( food );
food[0..1] = ['spinach', 'brocolli', 'apples'];   2
println( food );
food[4..20] = 'tomatoes';   3
println( food );

1

assignments to out of range indices are ignored

2

the size of the slice being assigned need not match the size of the assigned sequence

3

out-of-range portions of slice assignments are ignored. as in all cases where sequences are required, singletons are automatically converted

As a result, the following is printed on the console:

[ cheese, soda, fries, cupcake ]
[ cheese, soda, eggplant, cupcake ]
[ cheese, soda, eggplant, cupcake ]   1
[ spinach, broccoli, apples, eggplant, cupcake ]   2
[ spinach, broccoli, apples, eggplant, tomatoes ]   3

The value of the assignment expression is the value of the variable, element, or slice after the assignment. The type of the assignment expression is the type of the variable, element, or slice.