CO631 Anonymous Questions and Answers Keyword Index |
This page provides a keyword index to questions and answers. Clicking on a keyword will take you to a page containing all questions and answers for that keyword, grouped by year.
To submit a question, use the anonymous questions page. You may find the keyword index and/or top-level index useful for locating past questions and answers.
Keyword reference for replicator
2004 |
Hi, could you just give an explanation of how the following code works (taken from "sort_pump.occ"):
PROC sort (CHAN OF BYTE in, out) [total - 2]CHAN OF BYTE c: PAR cell (in, c[0]) PAR p = 1 FOR total - 3 cell (c[p - 1], c[p]) cell (c[total - 3], out) :
Thanks.
This code creates a pipeline of processes (of `total - 1' cells) -- see slides 5-17 and 5-18. The two end cells are catered for specially (since these plug into the external environment -- via `in' and `out'). The cells between these are created using a replicated PAR. If you substitute a constant value for `total' (say 10), then expand and flatten the PAR replicator, it becomes a bit clearer:
[8]CHAN OF BYTE c: PAR cell (in, c[0]) cell (c[0], c[1]) -- PAR p = 1 FOR 7 cell (c[1], c[2]) -- cell (c[p - 1], c[p]) cell (c[2], c[3]) cell (c[3], c[4]) cell (c[4], c[5]) cell (c[5], c[6]) cell (c[6], c[7]) cell (c[7], out)
Keywords: sort-pump , par , replicator
Just a quick question regarding sort_pump.occ. In the window process, does the following fill the buffer array with end markers?
SEQ SEQ i = 0 FOR buff.max buffer[i] := end.marker ptr := 0
If so, what is the point of doing so?
Also, what does ptr mean? Is it some kind of field to keep track of the index of the array? Thanks.
Yes. The statement "buffer[i] := end.marker" is replicated buff.max times in SEQuence, each with a different value for the control variable i (starting with zero, in this case, and incrementing by one each time).
We have to put something in the buffer since what is there initially gets pumped into the sorter as we type characters. We need something visible for display -- so zeroes (ASCII nulls) would not work. End markers work (they are mapped to visible dots for display) and they are harmless -- just ignore them (as does the lay.out process does if it sees consecutive markers!).
Note that in occam, there is no auto-initialisation of variables to default values (such as zero).
The answer to your last question is yes -- see the code labelled display buffer and update buffer, further down in the window process.
Keywords: replicator , sort-pump
2003 |
I was having problems putting the processes together using a replicator and was wonder if the code in the secure.college PROC create 6 philosophers instead of 5 as its is from 0 to 5
Replicators in occam are as they seem: replication `FOR 5' means you get 5 replications.
By default, the replicator value increments by one, with the first replication having the `start' value. The general syntax for a replicator in occam is:
SEQ|PAR|ALT|IF  name  = start FOR count
KRoC/Linux additionally supports ``STEP stride'' for replicators.
Keywords: replicator
Last modified Mon May 15 17:39:48 2006
|