Groups

We have already seen in previous chapters how groups can be used as a way to assign values to several object variables at the same time. In fact, the mechanism is more general and associated to the concept of broadcasting that we will define precisely in the next section.

First, a few words about groups. We have already seen how we can define groups with the group command. In the same way, you can simply add a member in an already existing group with the addgroup command, and remove one with delgroup, which allows you to handle dynamic group creation, if you ever need to:

group a { a1, a2 };
addgroup a { c, d };
delgroup a { a1, d };

You can examine the content of a group by invoking the group command with the group name only:

group a { u, v, b };
group a;
[01299618] ["u","v","b"]

Group subgrouping is possible, in that case the group content evaluation will return the list of terminal members only:

group a { u, v, b };
group b { x, y };
group a;
[01359471] ["u","v","x","y"]

A classical usage of the above feature is to iterate through a list of device objects, like motors, who have been gathered in the same motors group:

for m in group a
{
  echo (m);
};
[01426875] *** u
[01426875] *** v
[01426875] *** x
[01426875] *** y

Note: The $ construct will return the variable whose name is the string given as parameter. In the above example, we suppose that there is a .val alias, otherwise you would use: $(m+".val")

Now, we will see how you can make pratical use of groups with broadcasting.