Task: Add the 4th element to the collection, setting its value as the sum of the values of the 1st and 2nd elements in the collection.

This is already a complex expression, and before implementing it, let’s create a plan for its realization:

f1(f2(c, i1), f2(c, i2))

where:

As a result, the 4th element in the collection should have a value equal to 27.

Let’s follow the steps to implement the expression:

  1. Add a new element to the collection using the action «Add element».

  2. Set the parameter «Collection» for the action «Add element 4». Click on the button with three dots, and then select «Add element 3» from the robot’s actions. 

  3. Set the parameter «Value» for the action «Add element 4». Click on the button with three dots, and then click the button - call the expression constructor.

  4. In the pop-up window, select: «Operations/Arithmetic/Addition» and double-click the implementation of the action using the left mouse button:

  5. Additional fields for setting operand values will appear in the upper-left corner:

  6. In the field of the first operand of the operation «Addition», we need to extract the first element from the collection. To do this:

7. Repeat the same steps for the second operand of the operation «Addition»:

But this time, set the index of the collection to 1:

8. After entering the operand values for the operation «Addition», click the «Save» button and save the result in the resource variable C. The fourth element is added.

9. A new artifact «Expression_Add element 4_Value» appeared on the robot scheme.

10. Run the robot and check the result:

We can see that the collection now has the 4th element, and its value is 20 - the sum of the 1st and 2nd elements in the collection, set earlier.