Operators: =

Assignment operator.




The assignment operator = assigns the value of the right operand to the left destination operand. If the destination operand is a variable, an array, a local variable or a local array, then the value is written directly into the memory of the affected variable or array. If the left operand is a property, then the property associated onset method is called with the value passed in its value parameter. For example:

var   string localVariable;
array rect   localArray[4];

// Assign a value to a local variable
localVariable = "Hello World";

// Assign a value to a local array element
localArray[0] = <100,200,110,220>;

// Assign a value to an object variable
someObject.ColorVariable = SomeTextView.Color;

// Assign a value to an object array
someObject.StringArray[5] = SomeTextView.String + "!";

// Assign a value to a property
SomeTextView.Bounds = Bounds.orect;

Implicit type conversion

The Chora assignment operator subjects the value of the right operand to an implicit (automatic) type conversion if the data type of the right operand does not match the data type of the destination operand. For example:

var int32 a = 1369;
var float b;

// Convert automatically the int32 value to the float data type
b = a;   // b = 1369.0

Chained assignment

An assignment operation can be embedded as operand within another more complex operation. In this way a single expression can perform multiple assignments to multiple variables or the assignments can be chained. Following example demonstrates the function. Here you can consider the single expression as being composed of two partial expressions d = a + b and e = d + c:

var int32 a = 10;
var int32 b = 20;
var int32 c = 30;
var int32 d;
var int32 e;

e = ( d = a + b ) + c;  // d = 30, e = 60

When chaining assignment operators you should note the data type resulting from the nested assignment. As explained in the section above the assignment operator performs an implicit type conversion to ensure that the assigned value does correctly conform the data type of the destination operand. If this assignment is part of another more complex expression, the value it represents as operand within this expression is the value after the implicit type conversion took place.

The following example performs a chained assignment of the value 300 first to an int8 integer variable b and then the result of this operation to an int32 variable c. During the assignment to the variable b the assigned value is converted to fit in the 8-bit integer. Since it is too large, the value 300 is truncated and results in the value 44. This value 44 is consequently assigned to the variable c:

var int32 a = 300;
var int8  b;
var int32 c;

c = b = a;  // b = 44, c = 44

Compound assignment

Besides the above explained simple assignment operator = Chora also supports a set of compound assignment operators. These operators combine the assignment = with another regular operation. When executed, the operator first performs the regular operation with the both operands found on its left and right side and then, in second step, assigns the result of the operation to the operand on its left side.