Think Stitch

The Reuses of Processes by Renaming

You can reuse processes by renaming. Suppose you have a process which has exactly the same behavior you desire except the events and channels it uses. You cannot reuse it as is, but you can reuse it if you rename the events and channels, which means you can adjust interfaces of processes using renaming.

An Example: Buffers

Suppose, for example, we have a buffer process as follows:

(define-process P
  (? in (x) (! out (x) P)))

The computation tree is as follows:

You cannot reuse this process if the other party requires a channel mid as an output channel. However you can connect it to the other party by renaming the channel out to the channel mid.

(define-process R
  (rename `((,out . ,mid)) P))

The computation tree is shown in the next figure. Note that the state after sending through the channel mid is the same state as R. They look different just because the initial state is shown as the defined name. You can see that they actually the same state on the process tree, where the argument process of the rename node is P.

Next, we make a process consisting of two Ps. We can combine them by renaming both out of the first P and in of the next P to mid.

(define-process S
  (par (list mid)
    (rename `((,out . ,mid)) P)
    (rename `((,in . ,mid)) P)))

A rename has its own node on a process tree. You can inspect and capture the rename-map through the context menu of the node.

Multi-step Concatenations of Buffers

That is all for the reuses of processes by renaming. Taking the opportunity, we consider a case in which buffers are concatenated as a chain. For that purpose, three channels used for the medium are prepared.

The process definition is shown below. It looks complicated, but they are just combined from the tail to the head in turn. The intermediate channels are hidden. The channel in of the head and out of the tail remain visible.

(define-process SYS
  (hpar (list mid)
    (rename `((,out . ,mid)) P)
    (hpar (list mid2)
      (rename `((,in . ,mid) (,out . ,mid2)) P)
      (hpar (list mid3)
        (rename `((,in . ,mid2) (,out . ,mid3)) P)
        (rename `((,in . ,mid3)) P)))))

As you might expect, this process is actually a queue. Let's check this. Firstly we define a queue process. This is similar to the stack example in the SyncStitch User Guide. The only diffrence is the received data is added to the tail in the queue, while it is added to the head in the stack.

The computation tree is as follows:

The result says these two processes are the same.

9 August, 2013