XML

kent logo

CO538 Anonymous Questions and Answers

This page lists the various questions and answers. 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.

We have taken the liberty of making some minor typographical corrections to some of the questions as originally put. Although most of the questions here will have been submitted anonymously, this page also serves to answer some questions of general interest to those on the course.

When asking questions, please do not simply paste in your code and ask what is wrong with it, as these types of question are hard to answer in a public forum (resulting in either no answer, or an answer which will only be of use to the person asking the question). In many cases, a question about code can be formulated in general terms. For example, if you have an `IF' block that results in an `incorrect indentation' error, you might ask, ``what is the correct syntax for an occam `if' statement ?''. Questions of this form are easier to answer, and are meaningful to all.

Questions that are not suitable for these public pages (i.e. those that contain assignment-specific code), should be mailed to your seminar-leader.


Question 41:

Referring to Assignment on Q4:

  1. Are we allowed to implement a minus process? - I did
  2. Should I use an array of output channels in my monitor? - I'm defining 3 seperate outputs
  3. Should I use protocols for the channel types? - I figured that since my channel types are mostly very simple (i.e CHAN OF INT, BYTE) that I could leave it as it is. Will I be penalised for that?

Answer 41:

Yes, you may well need to implement a `minus' process, but it depends on how you go about solving that bit. For monitor outputs, a channel-array or separate channels are equally valid. On your third point, technically `INT' is a protocol. The structured PROTOCOL types should only be used if you need them -- you don't need them for this assignment.

Keywords: q4


Question 42:

Which diagrams do I need to submit with this assignment? (Q4)

Answer 42:

You should submit diagrams for all processes you create or modify. I.e., the modified process networks for `numbers', `integrate' and `pairs', and the overall top-level `q4' network. Also include `icons' for processes you create, if these aren't immediately obvious in the other network diagrams.

Keywords: q4 , diagrams


Question 43:

Will I be penalised if I use STOP to create a deadlock for Question 4?

Answer 43:

No, but it's not a very nice way of inducing deadlock, and it's not always correct. In the default `error-mode', processes that STOP cause a run-time error and the whole program finishes. In `stop' error-mode (which isn't the default), processes that STOP just die quietly, leaving the rest of the program running. Thus, if you use STOP, you should do it in such a way that the program would deadlock `nicely'.

A quick way of causing local deadlock is to communicate on an unconnected channel, simply:

    CHAN OF INT dummy:
    dummy ! 42                   -- deadlocks here, because there's nothing connected to the other side

Keywords: q4 , stop


Question 44:

Additional to Q40, I havn't actually started using `layout.max.chans' yet, because none of my deltas will work. Currently I've got numbers outputting into the delta I gave which outputs one channel into an output module which just outputs whatever ints it gets onto the screen straight away and the other output going to nowhere. If I remove the delta i get the output i expected, but with the delta in between I get no output. The only thing that can possibly be wrong is the delta. Any more ideas?

Answer 44:

If you leave the second output of the delta unconnected, the delta will get blocked when it tries to output. If you want to discard the data, connect it to an INT style black-hole:

    PROC int.black.hole (CHAN OF INT in)
      WHILE TRUE
        INT v:
        in ? v
    :

Keywords: q4 , deadlock


Question 45:

I have done the rest of the assignment but Im have trouble with pairs.mod, I have defined new PROC's:

    [snip code]

Below is my code for `pairs.mod':

    [snip code]

    PAR
      replace.bool (l.2,control,l.1)

      [snip code]

      SEQ
        prefix.bool(TRUE, l.2, l.1)
        delta.bool(l.1, l.2, l.3)

The trouble I have is that it says I have parallel inputs on channel `l.1', but this is similar to the way I implemented the other mods and they all work...

Answer 45:

This can't be right -- both these processes run for ever, so it doesn't make sense to execute them sequentially. Once `prefix.bool' starts, control can never return, so `delta.bool' never runs.

There appear to be two parallel OUTputs on channel `l.1', in replace.bool and prefix.bool

Keywords: q4


Question 46:

I'm having trouble with the `overflow.buffer' process in q5. Here is what I have; there seems to be a problem with `count' such that it doesn't get incremented and nothing ever gets outputted. Thanks.

    [adjusted code]

    PROC overflow.buffer (...)
      VAL INT BUFSIZE IS 10:
      [BUFSIZE] BYTE Buffer:
      INT head, tail, count:
      SEQ
        head:= 0
        tail:= 0
        INT count:
        count := 0
        WHILE TRUE
          ...  do things
    :

Answer 46:

Inside the body of the WHILE loop, `count' is undefined [1]. The assignment `count := 0' is assigning to the `count' declared immediately above it. In occam, the scope of a variable is the process that follows it. Assignment is a process (simple), as are SEQ blocks, etc. (processes that contain sub-processes). Thus, the scope of the first `count' declaration is the entirity of the SEQ body (in effect, all the code in `overflow.buffer'). When `count' is declared again inside the SEQ, it descopes the earlier `count'. The scope of this is, as always, the process that follows it, which is just the single assignment `count := 0', which of course leaves the earlier `count' untouched.

  1. By default, the occam workspace is initialised to 0x80000000 (MOSTNEG INT). Thus, count will likely be this value -- but it should always be considered undefined (with an unknown value). The Linux version of KRoC now has an undefined usage checker which will spot these sorts of error. Pre-releases of KRoC/Linux are better at this sort of thing.

Keywords: q5 , variable-scope


Question 47:

I have written my `q6' using a pipeline of cells with the cells written in a similar style to the `display' PROC (with IF statements to decide whether to send the incoming values on).

It compiles with no problems, but when I run it I get:

KROC: Range error / STOP executed (signal 4)
KROC: Fatal error code 1, core dumped
Abort (core dumped)

What is the likely reason for this ? I've checked through my code and it seems to be fine.

Answer 47:

Please refer to Question 30 (2003).

Keywords: q6 , range-error


Question 48:

I'm stuck on q6. My program deadlocks and I don't know why. I have managed to work out that it is something to do with my `cell' procedure, and also it appears to me that the `string.equals' procedure doesn't work in my cells. Any help would be great thanks.

    [snip code]

Answer 48:

Questions such as this are not easily answered in this public forum. Consider emailing your seminar leader.

However, in response to your query, when using `equal.string', etc., you must first ensure that `make.string' has been used on the string. These strings are not really strings -- they are arrays of BYTEs. `make.string' adjusts the array so that comparisons, etc. are based on the length of the `string', not the size of the array.

Keywords: q6 , string-handling

Referrers: Question 50 (2003)


Question 49:

For q6 i have just tried compiling my code and the compiler says

    no PROC or FUNCTION declared in sc module
    Incomplete program - no entry point

Whats all this about?

I have checked that their is a main function (i.e. q6 PROC has not been touched) i have only added a PROC and not done anything else.

Answer 49:

The most likely reason for this error is a missing colon `:' at the end of a PROC definition. PROC definitions should have the form:

    PROC name (formal parameters)
      ...  body
    :

Keywords: q6 , compiling

Referrers: Question 51 (2003)


Question 50:

To use `equal.string', I understand that I have to make the string from the array of bytes first using `make.string', but whenever I try to use `make.string' the compiler tells me that `make.string' is not a function. And indeed when I look at `string.occ' in the libsrc directory it is a PROC not a FUNCTION. Do I need to re-write `make.string' as a function or is there another way ??

Answer 50:

`make.string' adjusts an existing string (array of BYTEs) -- it does not create a new one. The function of this (if you read the source code) is to replace all the non-string bytes with a special token (ASCII NUL). In effect, it allows other routines to work out the length of the string -- which will likely be different from the size of the array.

For example:

    PROC string.test ()
      [15]BYTE s1:
      [10]BYTE s2:
      SEQ
        --{{{  initialise s1
	[s1 FOR 5] = "Hello"
	make.string (s1, 5)
	--}}}
	--{{{  initialise s2
	s2 = "HelloWorld"
	make.string (s2, 5)
	--}}}
	IF
	  equal.string (s1, s2)
	    good ()
	  TRUE
	    bad ()
    :

See also the answers to Question 48 (2003) and Question 19 (2001).

Keywords: string-handling

Referrers: Question 55 (2004)


Question 51:

referring to Question 49 (2003)

I have checked this and they all seem to be their for all the procs.

Answer 51:

In that case, I'd suggest mailing your seminar leader with the code.

One other, remote, possibility is that you're (accidently) trying to compile a non-occam source file.

Keywords: compiling


Question 52:

How do we know/check if an array is empty ?

Answer 52:

The `SIZE' operator in occam will return the number of elements in an array. If zero, then you know the array is `empty' (or more correctly, zero-sized).

Unlike Java, there is no concept of null-ness in occam, and you can't declare sizeless arrays. Parameters are slightly different, you can have:

    PROC n.elements (VAL []INT array, INT count)
      count := SIZE array
    :

But not:

    PROC blah ()
      []INT array:
      SEQ
        ...  stuff
    :

occam will not let you declare a zero-sized array either, for example:

    PROC blog ()
      [0]INT array:
      SEQ
        ...  stuff
    :

Keywords: arrays , size

Referrers: Question 69 (2010)


Question 53:

Hi, a question about Q6:

I want to store the in channel. I have written the following line:

    in ? string; temp.name.length::temp.name; temp.score

The compiler says it that string has not been defined. Yet in the `read.data' process, `string' is used and is not defined within the process. It doesn't work without the string either as it the compiler says:

    Simple input is not allowed on a channel with a tagged protocol

Any help please?

Answer 53:

The second of the two errors is more meaningful -- the `in' channel is of a tagged-protocol. The protocol in this case is `NAME.NUMBER', defined in q6.occ as:

PROTOCOL NAME.NUMBER
  CASE
    string; INT::[]BYTE; INT  -- string; name; number
    poison                    -- sent, and only sent, as the last message
:

The `string' referred to is the one in the above protocol definition.

There are two forms of tagged input in occam. The first allows for multiple CASEs; the second for a specific CASE only. For example, from the `display' PROC (in q6.occ):

    in ? CASE
      --{{{  poison
      poison
        ok := FALSE
      --}}}  
      --{{{  string; name; number
      --{{{  variables
      [max.name.length]BYTE name:
      INT name.length:
      INT mark:
      --}}}  
      string; name.length::name; mark
        SEQ
          out.string ([name FOR name.length], max.name.length, out)
          out.int (mark, max.name.length, out)
          out.string ("*c*n", 0, out)
      --}}}  

This shows the first form of tagged input -- where the `display' process handles both tags. The second form is just for a single tag, but not to dissimilar:

    --{{{  variables
    [max.name.length]BYTE name:
    INT name.length, mark:
    --}}}  
    SEQ
      in ? CASE string; name.length::name; mark
      ...  do something

Also see the answers to Question 26 (2002) and Question 18 (2001).

Keywords: q6 , protocol

Referrers: Question 57 (2003) , Question 58 (2003) , Question 59 (2003)


Question 54:

How do we view the `course.lib' file ? I have tried opening in eXceed (with and without gvim). What do we open it with ? Also, what do we use the processes for strings from the `course.lib' file for ? Thank you in advance.

Answer 54:

You can't view the file `course.lib' sensibly. It's a form of Transputer library file (like a Java .jar I guess) -- only useful to the compiler and associated tools.

The source code that makes up this library is readily available, on raptor, in the directory:

    /usr/local/courses/co516/libsrc/

In response to your second question, you need the string PROCs and FUNCTIONs in order to manipulate the BYTE arrays -- occam does not have a built-in `STRING' type, so like C, we make do with arrays of BYTEs.

Arrays in occam are generally fixed-size, but the string contained inside them may well be smaller (as is generally the case in q6). The string utilities deal with this nicely, so you don't have to.

For specific information on the string utilities, read the documentation provided in the `string.occ' file (in the directory mentioned above).

The answer to Question 19 (2001) might also be useful.

Keywords: q6 , course-library


Question 55:

For q6 do we need some form of end marker ? like the sort pump. If so how do we represent an end marker?

Answer 55:

Yes, you do need an `end-marker'. It is provided for you, however -- as the `poison' tag. The `read.data' process will output this once it has finished reading all the names (before terminating). The `display' process, when it receives this tag, also terminates.

See also the answers to Question 53 (2000) and Question 61 (2000)

Keywords: q6 , poison


Question 56:

Why can't you have multiple lines under a guard for example? It always says incorrect indentation.

    IF
      (equal.string(name, ""))
        copy.string(temp.name, name)
        copy.string(temp.score, score)
        copy.string(temp.name.length, name.length)

(just example code)

How can I get it to do all of these functions?

Answer 56:

See the answer to Question 1 (2000).

Keywords: sequential-execution


Question 57:

In response to the answer to Question 53 (2003):

I have implemented the `CASE' as suggested and is all ok until it gets to the poison condition:

    poison
      out ! name.length::name; score

I get the error:

    I/O list does not begin with a tag

(in reference to the second line)

What does this mean? Thank you :-)

Answer 57:

It means that your I/O list does not begin with a tag! -- An I/O list is the list of operands/expressions after an input `?' or output `!' operator. A tag is a label from a tagged (case) protocol definition.

In a similar way to case (tagged) input, you must specify the tag when using a tagged protocol. Change your second line so it reads:

    out ! string; name.length::name; score

Keywords: protocol


Question 58:

This is probably stupidly simple but my mind has gone blank. I've got an input of type NAME.NUMBER in q6 coming into my cell. I've taken the first INT and put it into a variable, now I want to take the next so many inputs (the number represented by the int) which is the name and put them into a list of char variable. How do I do it? Is there a line of code which will add one char to the end of a list?

Answer 58:

I think there is some confusion here. Just for the record, occam has neither char or list types. What it does have are BYTEs and arrays.

You say that you read the first INT into a variable, but I can't see how that would compile -- there would be a protocol mismatch (or other) error. The purpose of a counted-array communication/protocol (as described by `INT::[]BYTE') is to communicate both a length and that number of array elements. Thus, you do not need to do this yourself; all you need do is ensure that the inputting side's array is large enough to hold anything the outputter might send (a run-time error occurs if this is not the case).

As a fairly basic (!) example, consider:

    #USE "course.lib"

    PROC hello (CHAN OF BYTE kyb, scr, err)
      PROTOCOL TEST IS INT::[]BYTE:
      CHAN OF TEST c:
      PAR
        --{{{  output process
        VAL []BYTE str IS "Hello, counted-array world!*n":
        c ! (SIZE str)::str
        --}}}  
        --{{{  input (and report) process
        [64]BYTE tmp.str:                         -- should be large enough
        INT tmp.len:
        SEQ
          c ? tmp.len::tmp.str
          out.string ("The message was: ", 0, scr)
          out.string ([tmp.str FOR tmp.len], 0, scr)
        --}}}  
    :

See also the answer to Question 53 (2003).

Keywords: q6 , protocol


Question 59:

When trying to implement a cell I get the error:

    Error-oc-q6.occ(160)- Simple input is not allowed on a channel with a tagged protocol

on:

    in?string; length::name; mark

Answer 59:

See the answer to Question 53 (2003)

Keywords: protocol , q6


Question 60:

Are there any network diagrams that we need to hand in as well for q6? The q6 PROC is already drawn out in the file, and the `collate.marks' changes depending on the max number of names.

Answer 60:

No, you do not need to submit any additional diagrams for this assessment.

Keywords: q6

Valid CSS!

Valid XHTML 1.0!

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.
Last modified Mon May 20 13:50:23 2013
This document is maintained by Fred Barnes, to whom any comments and corrections should be addressed.