This is an old revision of the document!


Select statement

The select statement provides a selective wait for one or more alternatives. The statement may contain a series of alt clauses called branches. Each branch may be guarded. These guards divide branches into open and closed ones. A branch is called open, if it does not have a guard attached or its guard evaluates to True. Otherwise, a branch is called closed. To avoid indeterminism, if more than one branch is open the first of them is chosen to be executed. If all branches are closed, the corresponding agent is postponed until at least one branch is open.

A guard is a Haskell logical expressions placed inside round brackets.

Any communication through a port can be a pure communication or a value passing combination.

In case of a pure communication, the out statement sends a signal (without specified value) through the statement port.

In case of a value passing communication, the out statement sends a value of the statement parameter (or a literal) through the statement port).

The out statement is a single-step statement.

select {
  alt (g1) {...}
  alt (g2) {...}
  ...
}

Listing 1. Select statement syntax: g1, g2 stand for guards

Very often the ready function is used as a guard. The function takes a list of agent ports' names with in/out directions and returns True if at least one of them is ready for a communication immediately. For example, the guard (a and b are ports of the corresponding agent):

ready [in(a), in(b)]

evaluates to True if the agent can collect immediately a signal/value from at least one of these ports – It means that another agent has already provided a signal/value.

Example

Figure 1. Example communication diagram

agent A {
  loop {
    delay 10;
    select {
      alt (ready [out(a)] { out a; }
      alt (ready [out(b)] { out b; }
    }
  }
}

agent B {
...

Listing 1. Example code layer

In the above example, the A agent sends a signal through either the a or the b port depending on the requests of agents B and C. If both port are ready, the a port is chosen.

See also: In statement, Out statement

Go back