In HDevelop, an assignment is treated like an operator. To use an assignment, you can either type it directly into the program window or use the operator assign (Input, Result). Should you choose to work with the operator window, the operator has the following semantics: It evaluates Input (right side of assignment) and stores it in Result (left side of assignment). However, in the program text the assignment is represented by the usual syntax of the assignment operator: Result := Input. The following example outlines the difference between an assignment in C syntax and its transformed version in HDevelop:
The assignment in C syntax:
u = sin(x) + cos(y);
Can be directly typed in the program window as:
u := sin(x) + cos(y)
Another possibility would be to use the assignment operator:
assign (sin(x) + cos(y), u)
If the result of the expression does not need to be stored in a variable, the expression can directly be used as input value for any operator, or be typed into the program window. Therefore, an assignment is necessary only if the value has to be used several times or if the variable has to be initialized, for example for a loop.
Modifying tuple elements:
Inside the program window enter:
Result[Index] := Value
Another possibility would be to use the assignment operator assign_at:
assign_at (Index, Value, Result)
When using the operator window enter the operator assign_at and fill in the fields.
As an example:
Areas := [1,2,3] Areas[1] := 9
sets Areas to [1,9,3].
To construct a tuple with assign_at, normally an empty tuple is used as initial value and the elements are inserted in a loop:
Tuple := []
for i := 0 to 5 by 1
Tuple[i] := sqrt(real(i))
endfor
As you can see from the examples, the indices of a tuple start at 0.
An insertion into a tuple can generally be performed in one of the following ways:
assign ([Tuple,NewVal],Tuple)
which is displayed as
Tuple := [Tuple,NewVal]
To insert the tuple [11,12,13] into the tuple [1,2,3] at position 1, use
tuple_insert ([1,2,3], 1, [11,12,13], Result)
or as in-line operation
Result := insert([1,2,3], 1, [11,12,13])
resulting in [1,11,12,13,2,3].
In the following example, regions are dilated with a circle mask and afterwards, the areas are stored into the tuple Areas. In this case, the operator assign_at is used.
read_image (Mreut, 'mreut')
threshold (Mreut, Region, 190, 255)
Areas := []
for Radius := 1 to 50 by 1
dilation_circle (Region, RegionDilation, Radius)
area_center (RegionDilation, Area, Row, Column)
Areas[Radius-1] := Area
endfor
Please note that first the variable Areas has to be initialized to avoid a runtime error. In the example, Areas is initialized with the empty tuple ([]). Instead of assign_at, the operator assign with tuple concatenation could be used because the element is appended at the end of the tuple:
Areas := [Areas,Area]
More examples can be found in the program assign.hdev.