In HDevelop, an assignment is treated like an operator. To use an assignment you have to select the operator assign (Input, Result). This 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);
is defined in HDevelop using the assignment operator as
assign (sin(x) + cos(y), u)
which is displayed in the program window as:
u := sin(x) + cos(y)
If the result of the expression does not need to be stored into a variable, the expression can directly be used as input value for any operator. Therefore, an assignment is necessary only if the value has to be used several times or if the variable has to be initialized (e.g., for a loop).
The assignment operator assign_at (Index, Value, Result) is used to modify tuple elements. The call:
assign_at (Radius-1, Area, Areas)
is not presented in the program text as an operator call, but in the more intuitive form as:
Areas[Radius-1] := Area.
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)
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
Areas := [Areas,Area]
could be used, because the element is appended at the back of the tuple. More examples can be found in the program assign.hdev.