The way to reuse processes by the sequential compositions has a drawback. Reused processes (callee processes) have no way directly to pass data to caller processes.
For example, consider a subprocess SUB which role is to receive data through a channel rch and pass the received data to the caller, P say.
(define-process P (seq SUB ???)) (define-process SUB (? rch (x) ???))
The process SUB cannot pass the received data x to the caller process P. This problem can be solved using a memo process.
A Memo process, as its name suggests, is a process which records data from a client process and returns it when the client requests.
Typical structure of processes using a memo process is as follows:
Firstly the caller process call the callee process. If you want to pass data from the caller to the callee, you can pass it through the process parameters of the callee process. (which is indicated a dotted line in the figure.)
The callee process passes the data to be passed to the caller as a result of a job to the MEMO process through the channel mwr. After that the callee process terminates via SKIP. This returns the controll to the caller process.
The MEMO process runs concurrently against the pair of the caller and the callee. The caller process can retrieve the data generated by the callee through the channel mrd from the MEMO process.
The MEMO proces has a process parameter m which holds data from a client. The MEMO proces can receive both read and write request any time. The read request is received through the channel mrd. Since the read operation is "receiving" from the client, it is sending for the MEMO process. The write operation is received through the channel mwr, and it changes the value of the process parameter.
(define-process (MEMO m) (alt (! mrd (m) (MEMO m)) (? mwr (x) (MEMO x)) ))
The computation tree of the MEMO process is as follows:
The process SUB receives data through the channel rch and passes it to the caller via the MEMO process. After sending the receved data to the MEMO process, the process SUB terminates via SKIP.
(define-process SUB (? rch (x) (! mwr (x) SKIP)))
The main process P firstly call the process SUB using seq. After that, P retrieves the data through the channel mrd from the MEMO process. The output through the channel ch is added in order to make sure that the main process was able to receive the received data.
(define-process P (seq SUB (? mrd (x) (! ch (x) STOP))))
Finally, we define the SYSTEM process composed of the main process P and the MEMO process. Since the process SUB is called from the main process, it is not included in the parallel composition.
(define-process SYSTEM (par (list mrd mwr) P (MEMO 0)))
A part of the computation tree of the SYSTEM process is shown below. You can see that P surely receives the data from SUB via MEMO (in this case, the value 1).