Broadcasting

When you execute a command at the level of a group, which can be a function call or an assignment, the command will be propagated in parallel to each element of the group and their subgroups. This is called broadcasting. This can also apply to classes, since you can define a group taking care of every sub class instanciation. A conventional practice is to name the group associated to a class with the plural of the class name, usually adding a simple 's'.

First, let's see how assignements are broadcasted. Consider the following example:

class a;
a1 = new a;
group as {a,a1};
a1.x = 42;
as.x = 4;
a.x;
[139464:notag] 4.000000
a1.x;
[146711:notag] 4.000000

Broadcasting on functions works similarily:

class a {
  var x;
  function f();
};

function a.f() {
  echo x;
};
a1 = new a;
group as {a,a1};
a.x = 1;
a1.x = 2;
as.f();
[139464:notag] *** 1.000000
[139464:notag] *** 2.000000

The above function call on f is in fact executed as:

a.f() & a1.f();

Broadcasting is duplicating the commands in parallel.

As usual, subgroups are explored in the process.

Broadcasting functions can be very useful to execute tasks in parallel in a group of objects, without having to use for& or similar constructs. Broadcasting and inheritance complement each other, so when the broadcasting is finished, the function definition can be searched upward in the class hierarchy, like in this example:

class a {
  var x;
  function init(v);
  function f();
};
function a.init(v) { x=v; };
function a.f() {
  echo x;
};
a1 = new a(1);
a2 = new a(2);
a3 = new a(3);
function a1.f() { echo "I'm different!"};
group oneandtwo {a1,a2};
oneandtwo.f();
[139464:notag] *** 2.000000
[139464:notag] *** I'm different!

Broadcasting is clearly a new feature in the hands of programmers. You might or might not use it, but we believe that it will help to make many codes more concise by grouping logical actions in one line, instead of using for loops or similar iterating concepts. It also makes clear that certain actions should be executed in parallel on a group of objects, which is semantically meaningful.