Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionBoth sides next revision | ||
alvis:select [2013/12/15 07:53] marcin created | — (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. | ||
- | |||
- | |||
- | |||
- | Any communication through a port can be a **pure communication** or a **value passing combination**. | ||
- | |||
- | In case of a **pure communication**, | ||
- | |||
- | In case of a **value passing communication**, | ||
- | |||
- | The **out** statement is a single-step statement. | ||
- | |||
- | < | ||
- | 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:** [[: | ||
- | |||
- | **[[: |