Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revisionBoth sides next revision | ||
| alvis:select [2013/12/15 07:54] marcin [Select statement] | — (current) | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== 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, | ||
| - | |||
| - | A **guard** is a Haskell logical expressions placed inside round brackets. | ||
| - | |||
| - | |||
| - | The **select** statement is a multi-step statement. The first step consists of evaluating the guards and entering the corresponding branch (if possible). Then, a model executes steps inside the branch. | ||
| - | |||
| - | < | ||
| - | select { | ||
| - | alt (g1) {...} | ||
| - | alt (g2) {...} | ||
| - | ... | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | **Listing 1. ** Select statement syntax: '' | ||
| - | |||
| - | 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 ('' | ||
| - | ready [in(a), in(b)] | ||
| - | evaluates to **True** if the agent can collect immediately a signal/ | ||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | ===== 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 '' | ||
| - | |||
| - | |||
| - | **See also:** [[: | ||
| - | |||
| - | **[[: | ||