Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Both sides next revision
alvis:proc [2013/12/29 20:55]
marcin [Proc statement]
— (current)
Line 1: Line 1:
-====== Proc statement ====== 
  
-**Passive agents** are used to store data shared among agents and to avoid the simultaneous use of such data by two or more agents. They provide a set of **procedures** that can be called by other agents. Each procedure has its own port attached and a communication with a passive agent via that port is treated as the corresponding procedure call. Depending on the communication direction, such a procedure may be used to send or collect some data from the passive agent. Moreover,  
- 
- 
- 
-<code> 
-proc (g) p {...} 
-</code> 
- 
-**Listing 1. ** Proc statement syntax, where ''g'' stands for a guard and is optional and ''p'' stands for the corresponding port name. 
- 
-A procedure is accessible for other agents only if the guard evaluates to ''True''. 
- 
-A communication between an active and a passive agent (a procedure call) can be initialised only by the former. Any procedure in Alvis uses only one either input or output parameter (or signal in case of parameterless communication). In case of an input procedure, an active agent calls the procedure using the **out** statement (and provides the parameter, if any, at the same time). If the corresponding passive agent is in the **waiting** mode and the procedure is accessible, the agent starts it in the active agent context. The passive agent collects the signal/parameter using the **in** statement, but it is not necessary to put the statement as the first procedure step. Similarly, in case of an output procedure, an active agent calls the procedure using the **in** statement. The passive agent returns the result using the **out** statement, but it is not necessary to put the statement as the last procedure step. 
- 
-===== Example ===== 
- 
-This is a part of a model only! 
- 
-{{:alvis:buffer.png|}} 
- 
-<code> 
-agent Buffer { 
-  i :: Int = 0; 
-  proc pop  { out pop i; } 
-  proc push { in  push i; } 
-} 
-</code> 
- 
- 
-**[[:alvis:manual|Go back]]**