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 21:

I am having trouble with step 3 of the assessment. I am trying to have a variable that is set to either 1 or -1, and then the one of the numbers within pairs is multiplied by this number before the addition takes place (having the effect of subtraction).

My trouble comes in where to create and initialise the variable (call it `b'). At the moment I have it in my monitor process...

    [snip code]

but when I compile, it whinges on the line marked that `b' is not declared. Doesn't the declaration at the top of the PROC last throughout the process ?? If not, how can I introduce the `b' variable without it being reset to one each time the process is run??

Answer 21:

The rule with variable declarations in occam is that they are visible in the process following the declaration, and only that process.

For a good description of this, which relates directly to the error in your code, see Question 3 (2000). You should have gotten an error about incorrect indentation in that code too..

Keywords: q4

Question 22:

Can you tell me why I get the following error message ?

    black.hole(interrupt) -- type mismatch for parameter 1 in call of black.hole

Answer 22:

The PROC header for `black.hole' is:

    PROC black.hole (CHAN OF BYTE in)

The only reasonable explanation is that you're trying to pass a channel parameter that's not a `CHAN OF BYTE'. If you need an INT `black.hole', this can be easily created by modifying the existing `black.hole', but make sure you call yours something different (like `int.black.hole', for example). The source for the existing `black.hole' can be found on raptor in:


(or, from windows, `\\raptor\files\courses\...').

Keywords: type-mismatch

Question 23:

Are we allowed to create a process called `my.prefix', and replace the standard `PROC prefix (...)' within `my.numbers' / `my.integrate' with the new `PROC my.prefix (...)' ?

Answer 23:

Yes, in theory there's no problem with doing that. However, for this assessment, there shouldn't be a need to do this, but that depends on how you go about modifying the various process networks.

Keywords: q4

Question 24:

How is it possible that If I run the process (without inputting anything) at a certain point I start getting negative numbers for the 2nd and 3rd column ?

Answer 24:

This is quite possibly normal behaviour. In standard 32-bit 2's complement signed arithmetic:

    1500000000 PLUS 1500000000 = -1294967296

In occam, you must use the `PLUS' operator to get this behaviour. The standard `+' operator will cause a run-time error when this happens, which is generally what you want.

You might want to consider slowing the output down with a suitable delay. See Question 13 (2000) for how to do this. In relation to Q4, the initial values output by the program should be correct, until something overflows that is. If the output goes negative very early on, then something is probably wrong -- check the values!

Keywords: overflow , negative-numbers

Referrers: Question 26 (2003)

Question 25:

I have now got a completed version of q4. However, in this monitor process...

    [snip code]

.... it will only reset `I' or `P' if I press the key twice and it pauses it inbetween each key press. How come it is doing this as it is only the `S' case that asks for a second input? Also, typing in N twice causes the program to deadlock, yet I can't think of why. Any suggestions?

Answer 25:

You have an ALT guard of the form:

    in ? y
      BYTE x:
        in ? x
        ...  do something based on `x'

Before getting to the `do something based on `x'' bit, two inputs will happen on "in". Remember that in an ALT, input guards do perform the input before the guarded process runs. The correct guard/process would be something like:

    in ? y
      ...  do something based on `y'

Keywords: q4 , alternation

Question 26:

Could you tell me why the following cose is outputting negative numbers?

    [snip code]

I really dont understand what's wrong with it!

Answer 26:

See the answer to Question 24 (2003). That should explain it.

Keywords: negative-numbers

Question 27:

I'm having some problems with the new pairs process. This is what I've done:

    [snip code]

It doesn't seem to be doing anything. Any suggestion ?

Answer 27:

This appears to be a common mistake -- you're instancing the `plus' and `minus' PROCs from inside another component, that results in your component behaving like either `plus' or `minus' respectively. However, once called, these PROCs never return, as they have WHILE TRUE loops.

If you want a single component to take care of the addition/subtraction, you have to engineer (program) it that way -- i.e. a single self-contained PROC, not one that instances other PROCs. If you do want to re-use the existing `plus' and `minus' PROCs, they have to be engineered into a suitable parallel network -- i.e. instanced directly under a PAR, not from sequential code.

Keywords: q4 , process-networks

Referrers: Question 29 (2003)

Question 28:

The compiler doesn't seem to like the following code:

    [modified code]

    PROC layout.max.chans (...)
        [max.chans]INT n:
        ...  SEQ process that reads values in PAR then writes them out
        PRI ALT
          int x:
            ...  guard and process

With an error of the form:

    layout.max.chans(...) -- layout.max.chans is not declared

Answer 28:

This isn't the real error. `layout.max.chans' isn't considered declared because the compiler couldn't parse/compile it. I see what you're trying to do, but this isn't necessarily the best place to do it.

If you really want to modify `layout.max.chans', the errors are incorrect indentation at the `PRI ALT' and `int x:' isn't a valid declaration. The first error is likely a missing `SEQ', or mis-placement of the `PRI ALT'. See Question 1 (2000) for more details on this. The second is easy -- `int' should be `INT', and the guard should be indented at the same level as the declaration, with the guarded process indented under that.

Keywords: undeclared , incorrect-indentation

Question 29:

I'm having trouble with getting the `pairs' process to toggle adding and subtracting. The following code compiles but doesn't do much, the only effect being that an input on the control line stops any other keypresses getting through. Ive tried declaring `subtract' in various places to no avail. Thanks.

    [snip code]

Answer 29:

See the answer to Question 27 (2003) for a brief description of the problem. Your code contains the process networks for both versions of pairs, but once running, these will never terminate -- they contain `WHILE TRUE' loops. You need to modify the process network itself -- not `wrap' the networks up in other code, as that won't work.

Keywords: q4

Question 30:

my program keeps aborting when i run it, it shows this ...

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

what is wrong here?

Answer 30:

This is the result of a run-time error in your occam program. These errors are caused by one of the following:

However, the error doesn't tell you where or exactly what the error is. Post-mortem debugging is available in KRoC, but only for the Linux version at the moment -- you can use `gonzo' for this. Compiling with the `-d' flag will turn on debugging such that when the program crashes, it'll display a more useful error message (including the file-name and line-number where the error occurred).

See also the answer to Question 70 (2000).

Keywords: range-error , stop

Referrers: Question 31 (2012) , Question 47 (2003) , Question 72 (2003) , Question 86 (2003)

Question 31:

I'm a bit confused about the `out.int' and `out.string' PROCs in `layout.max.chans' in Q4. Are they already defined somewhere, because I can't seem to find them. Or are we meant to define these two PROCs ?

Answer 31:

They are defined elsewhere -- in `course.lib' to be precise, so you must not define them yourself -- doing so will result in linker errors when it finds two copies of each (one from the course library and one from your code).

These two PROCs just write INTs or BYTE-arrays to a BYTE channel, aligning in the given `field' (2nd parameter). Writing `out.string' is easy, `out.int' less so. You can find the code for these on raptor in:


Keywords: out.int , out.string , q4

Question 32:

Just a small question, what is the bell character? i.e. the one that makes the terminal bleep? I was told it was BELL, but if thats true do we have to output it one letter at a time ?

Answer 32:

No; `BELL' is a BYTE constant. Please refer to Question 13 (2003).

Keywords: bell , beep

Question 33:

This is one of the statements under a PRI ALT in my code:

    BYTE y:
    in ? y
      out ! y

When I compile it tells me that `y' is not declare on the second line. However, I have exactly the same piece of code in another PROC with a `z' instead of a `y' and yet it compiles ok. Any ideas ?

Answer 33:

If that's a guard of a PRI ALT, there's nothing wrong with it. Thus, the error must be elsewhere. Errors above that, but possibly still inside the PRI ALT, might be confusing the compiler when it gets to this point. The first error output by the compiler is generally the most relevant -- others may simply be a cascade effect.

Keywords: alternation , variable-scope

Question 34:

    [snip code]

I'm probably missing something really obvious, but why is this not giving any output? There is nothing coming in through the input channel, but yet when I attatch it to a tested output module nothing comes out.

Answer 34:

Look carefully at the PROC heading for `replace':

    PROC replace (CHAN OF INT in, control, out)

and note the ordering of the `in' and `control' channel parameters.

Keywords: q4

Question 35:

I have:

    VAL INT state IS 0:

I'm hoping this is like an external field in Java, but I can't work out how to alter the value of state. ``state := 1'' and many other ways I can't get to work. How can I alter the value, or is there another way or storing a value outside of a proc.

Answer 35:

In occam, the only way you can make a variable global to a PROC is to have it in-scope. The `VAL' qualifier in occam effectively means constant, so your `state' isn't actually a variable -- it's a constant equal to zero. Removing the `VAL' won't work either, since occam does not permit variables to be declared at the outermost level.

You can do this sort of thing, but it probably won't work in the way you expect it to.. e.g.:

    PROC thing (...)
      INT state:

      PROC fiddle.state (VAL INT new.state)
        state := new.state

      ...  body of `thing'

In this code, the PROC `fiddle.state' has access to the `state' variable. However, the compiler's alias and parallel usage checking might prevent you from using `state' in the `body of `thing'' -- depending on usage of `fiddle.state'. In short, this is generally not a good way forward.

If you need a state variable for a PROC, just declare it inside the PROC and initialise suitably, e.g.:

    PROC thing (...)
      INT state:
        state := 0         -- default state
        ...  body of `thing'

Only useful if the `body of `thing'' is long-lived, however.

Keywords: global-variables

Question 36:

To suspend screen output, would directing the `out.int' and `out.string' to a `black.hole' be appropriate ? I have tried this but it doesn't seem to work, am I going in the right direction or completely off.

Answer 36:

Re-directing the output to a `black.hole' won't suspend it -- it'll gobble it up, like a black-hole. To suspend the output you need to stop the flow of data, which is often simpler than re-directing it. See the model answer for question 3 (on raptor) for an idea of how to do this.

Keywords: q4 , suspend

Question 37:

I've tried to install KRoC onto my computer at home running Mandrake Linux. I ran the `build' script, so it should be installed according to the installation instructions. But yet it still doesn't recognise the 'kroc' command. Sorry I'm new to linux, what have I done wrong (or more likely not done)?

Answer 37:

You suggest correctly that it's something which you've not done. Before you can use kroc, you need to source the setup file. More than likely, this will be something like:

    mandrake$ source /path/to/kroc/bin/setup.sh

replace `/path/to/kroc/' with the directory where you installed KRoC to -- which will be the source tree if you just hit return at the first question it asks you (about where to install).

Once that file has been sourced, the `kroc' command should work.

Keywords: mandrake-linux , linux

Question 38:

Do we have to use the replace function provided for q4 ?

I have a working q4 but it does not use the replace function. That ok?

Answer 38:

In theory, yes. However, if your solution would have been more efficient using `replace' you may lose marks based on that. However, if your solution is succinct and correct, no marks will be lost.

Keywords: q4

Question 39:

I've done the third mod and it works fine. However, someone has just mentioned that you didn't want us to modify the `plus' process. Is this true ?

Answer 39:

The question says:

  'p' ==> the first 'p' zaps the adder process within pairs so that it
          becomes a subtractor, taking the numbers arriving directly from
          the delta process away from those arriving from the tail.  In this
          state, the modified pairs becomes a `differentiator', undoing
          the `integration' effect of the process immediately upstream so
          that we see the natural numbers sequence.  A second 'p' toggles
          the process back to its original state.  Subsequent 'p's toggle
          between the two states.

There is not a single `right' way to do this. The first line seems to imply that you should modify the adder process, though there is a neat solution that doesn't.

Keywords: q4

Question 40:

    delta (g, h, c[0])

this is in my main q4 proc. `g' is the input coming from numbers, `c[0]' is an output which will go to layout.max.chans and `h' is an output which will go into integrate. I know numbers gives an output as I've tested it with an output module, but as soon as I attatch the output from number to the input of this delta neither `h' or `c[0]' give any outputs when tested with the same output module.

I can't for the life of me see what I've done wrong! I've checked that all channels are connected correctly over and over so its not that either. Any ideas?

Answer 40:

Two numbers must be output by the `numbers' process before any proper output appears. Since all the output is done via `layout.max.chans', that must input from each of its channels before anything will be displayed on the screen. Thus, if any of those input channels are unconnected, nothing will happen -- the `layout.max.chans' process will wait for input forever -- the `max.chans' constant defines how many channels should be `layed-out'. Similarly, if your pairs process doesn't output after two inputs, things will deadlock -- `layout.max.chans' will be waiting for that final input and the remainer of the network will probably be blocked on output.

Keywords: q4

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.