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

Will our room locations for the seminars starting in week 6 be posted in the Octagon, the co516 webpage, or will our seminar leaders email us ?

Answer 21:

These will be posted on the notice-boards in the Octagon. They should be up by Monday afternoon, if not before.

Keywords: classes


Question 22:

How do we test / check that Q1 is correct?

In Java if you were in BlueJ you would create objects and from a command line you'd type in a prompt. In a previous answer you said this Q doesn't take any input. So how are we meant to check what we've done is correct?

Answer 22:

See the answers to Question 16 (2004) and Question 20 (2004). You could also check if what you've done is correct by working out the numbers (on paper) and comparing with your program's output.


Question 23:

I understand when you say that only `screen' is used as an output channel and that `keyboard' and `error' are not used, but I don't see the connection between running:

    /usr/local/courses/co516/answers/a1

which produces a continuous list of numbers, and what we have to do check our `q1' works ?

Answer 23:

That program (`a1') is the model solution for Q1. Your program should produce the same output as it does (i.e. a continuous stream of numbers).

Keywords: q1


Question 24:

You said in the answer to Question 20 (2004):

To test `q1', just run it. It should produce the same output as the model answer.

To run a program in occam do we just type:

    kroc q1.occ

?

Answer 24:

Nope, `kroc' is the compiler. When you compile `q1.occ' you're left with an executable called `q1', assuming it compiled successfully. Just run it, i.e.:

    raptor$ ./q1

I'd ask what you've been doing in the terminal sessions for the last 3 weeks -- compiling and running occam programs is one of the first things we did. E.g. compiling and running the various demonstrator and example programs.

Keywords: running


Question 25:

Just some feedback,

Maybe you should have started the CO516 class with a few UNIX commands we'd need for occam since most of us have never used it before, CO501 never covered UNIX much in the first 4 weeks and the extra UNIX sessions so far have been 2 lectures and 1 class. Hardly enough to help us run and compile occam programs.

Also maybe instead of the first couple of terminal sessions getting us to correct `bugs.occ' (which we found hard as we hadn't done occam before so took a long time) it would have been better to have had more classes such as `demo.occ' to run and compile and maybe several programs with small errors rather than one big one with lots of errors.

Answer 25:

Thanks!

The Co516 did start off by getting you logged in to Unix (on raptor) and showing you how to navigate through your file store. Before coming to the classes, you were supposed to have followed the "occam setup information" link on the Co516 web page and copied over the examples and exercises directories to you home area. In the class, those who had not done this were nursed though it. You were then told to read through the various README files ... particularly the one in examples ... which explains how to compile and run occam programs.

That information is all you need to start work. Here it is again. To compile an occam source code file called "thing.occ", the command is "kroc thing.occ". This produces either compiler error messages or the compiled executable called "thing". To run your compiled executable, the command is "thing". Usually. Some users do not have the current directory in their command search path - in which case, "thing" produces a response saying that that command cannot be found. In which case, to run your compiled executable, the command is "./thing" (which tells the system to look in ".", your current directory, for the file "thing" and run it).

That's all there is to it! And that's what has been shown to you in the classes since week 2. If you didn't know, why are you asking now and not then. It's not possible to have been doing the work without knowing this. There are no other Unix skills needed. You need to be able to edit text files, of course, and there are several Unix editors on offer. But you can simply use your favourite Windows editor since you can operate on your (raptor) files from Windows.

The "bugs.occ" file consists of 23 lines of code. It's got lots of errors but it's not exactly big! Compiling/editing it was supposed to be a game hiding some solid learning experience. You just need the course slides in front of you and the "occam2 Checklist" paper and some enjoyment at solving puzzles ... it should never have taken two whole terminal sessions.

It seems that some students view the classes as the time when you do these exercises. That's true but, in between classes, is no further work done on them? You are supposed to put in several hours work in your own time for every one hour lecture. Apart from working on the computer, reading is essential ... through the course slides and the papers at the end of the course notes. The "occam Approach to Transputer Engineering" is an easy read, and goes through many of the lessons presented in the slides and lectures. There is also "Fred Barnes' occam tutorial", linked off the Co516 web page. Currently (Week 5), you are supposed to be reading the file "sort_pump.occ" in your examples directory. This follows the lecture last Tuesday. You need to study particularly the processes key.mix, window and layout. How many are doing this? To get ahead, look also at screen.mix ... but this requires an occam construct, the ALT, which we haven't done yet in the lectures.

Any problem you discover in your understanding of the subject, that you can't solve by asking your colleagues, can be asked on these pages -- but please check the keyword index first! Have you all looked at questions 1 through 9 (and their answers) from the "Year 2000-2001"? Lots of the questions asked this year already have answers there. There are also chunks of code directly relevant to answering Q1.

Finally, please bring specific problems that remain outstanding to the leaders in your terminal classes or, from next week (Week 6), your seminar groups.

Keywords: unix


Question 26:

Hi,

I've successfully installed KRoC on my Linux machine. But when I try to run the "kroc q1.occ -lcourse" command, for example, it tells me that it doesn't know the "kroc" command. Someone's told me that to overcome this I have to first type the command:

    source <path-to-where-I-installed-kroc>/bin/setup.sh

and that works.

But how do I set things up so that that command is automatically done whenever I open a new shell window? It's very tedious to type manually each time! I'm using the bash shell. Thanks.

Answer 26:

You need to arrange for the shell to execute this each time it starts up. The most effective method is just to add that command (`source /path/to/kroc/bin/setup.sh') to your `~/.bash_profile'. This may not start working immediately (some GUI environments start bash shells in non-login mode), but will do if you log out of X and back in again.

Alternatively, you can make it system-wide by putting the same command in `/etc/profile'.

Keywords: linux


Question 27:

When I run `./q1' I get the following error message:

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

Could you give me some hints about what's wrong with my code ?

    [snip]
    out !  BYTE x
    out !  BYTE y
    out !  BYTE z
    out !  BYTE avg 
    out !  BYTE '*n'
    [snip]

Answer 27:

The above outputs will definitely cause the problem. If the value in `x' were 0, this will output an ASCII-null -- which produces nothing on the screen, not the character `0'. If the value in `x' were 65, this will output the character `A' -- since 65 is (I think) the ASCII code for `A'. It will definitely not print out the string "65"! If the value in `x' were 1000, this will crash your program as you cast `x' to a `BYTE' -- occam BYTEs only take values between 0 and 255 inclusive. None of this is what you want!

You cannot, of course, dispense with your casting to a BYTE since the code will not then compile -- you cannot output INT values to a channel carrying BYTEs. That is not what you want to do anyway!

Your `out' channel is connected (from its instance in your `q1' process) to the top-level `screen' channel. To print INT values to such a channel, you must convert them to the characters (BYTEs) coding the decimal digits that we use to represent them. This is not trivial. Fortunately, there's a ready-made PROC in the course library that you can use to do this -- out.int. Suppose we invoke:

    out.int (x, width, out)

where `x' has the value 1234, say, and `width' is 6. This outputs ` ', ` ', `1', `2', `3', `4' to the `out' channel. The `width' in the argument list is the field width -- it outputs spaces before the number to make it that many characters wide (which is useful if you want to print right-justified columns of numbers). Have a look at `examples/test_utils.occ' for examples of using it -- and, of course, the model answers to Q1 from the exercise sheet.

To output strings, there is another library PROC. For example:

    out.string ("hello world", 0, out)

outputs `h', `e', `l', etc to the `out' channel. In this example, the field width, 0, happens to be less than the number of characters in the string -- in which case, it is ignored. If we had use a field width of 20, say, than 9 spaces would have been output first (making 20 characters in total).

Keywords: output , out.int , out.string


Question 28:

I have started to try exercise Q3 and am finding it a little difficult so I wanted to know if there is still material that you are going to cover that helps us with this or should we know enough by now to be getting on with it?

Answer 28:

Yes - we have done enough for you to tackle Q3. What you needed was the ALT or, more specifically, the PRI ALT. In fact, we've now done enough of the language for you to complete Q4 (which is for assessment and for which Q3 is a sub-part) and Q5.

In your seminar groups this week, you are being inrotduced to Q3 and working out how to solve it.

Keywords: exercises


Question 29:

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.

Answer 29:

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


Question 30:

In the diagrams that you have put into Q4, you have connected the `monitor' only to `numbers' `integrate' and `pairs'. Surely this also needs to be connected to the `layout.max.chans' as to allow output to the screen or not? That is the way I managed to do it in Q3 and it seemed to work ok.

Answer 30:

The keyboard characters input by the `monitor' process do not have to be echoed to the screen channel.

I assume you are talking about the suspend mechanism, in reaction to an `s' keyboard input -- the fourth modification. From `q3.occ':

  --{{{  data-flow diagram
  --
  --Sorry ... you're on your own here.
  --
  --}}}

So yes, some extra connectivity is required beyond that shown on the diagram for the third set of modifications.

However, altering `layout.max.chans' (to take that extra connectivity) is not the simplest approach -- the re-programming is untidy; since it takes its original inputs in PARallel, you will need to poll the extra one separately.

A simpler approach, as discussed in the seminars for Q3, is to create a separate `suspend' component that can be added to the existing process network (with some minor extra wiring) -- and leave `layout.max.chans' unchanged.

It's usually better engineering to add new functionality by adding a new (parallel) process specifically to implement it, rather than by modifying an existing component to add to its responsibilities. For performance reasons, we may sometimes need to fold parallel processes together into one single (but more complex) serial process -- but that can be done later (and fairly mechanically). In this exercise, there is no such performance constraint. In fact, the model answer adds code to slow the system down to produce output at only 10 lines/second, so that it's easier to see the effect of the controlling keystrokes. You might like to do the same -- though this is voluntary!

Keywords: q4


Question 31:

I'm in the middle of part 2 of Q4 and have run into a problem. When compiling im getting this error:

    Incomplete Program - no entry point.

I have gone as far as deleting everything except the very basic q4 PROC with the same error. Is there something wrong with this code?

    [snip code]

Answer 31:

That looks fairly strange.. I'd suggest checking the source file for stray characters (the occam compiler does not like DOS/windows style line endings).

Failing that, please mail me (frmb@kent.ac.uk) a complete dump of the terminal output (all errors, etc.) and attach the file that causes the problems; from that it should be pretty easy to work out what's wrong. Copy/paste is sufficient for terminal dumps, or use the `script' command (starts a sub-shell and copies input/output to a file called `typescript'; ctrl-D to exit the subshell).

Keywords: kroc


Question 32:

I'm now somewhat through Q4 and have noticed that I'm using polling `PRI ALT's. It says in the coures notes that they should be used only as a last result -- I'm wondering if this is acceptable in Q4?

I'm not sure of another way of interupting a process based on a signal that may or may not arrive. I've created PRI ALTs in the new control PROCs that have been added to `numbers', `integrate' & `pairs'. I'm now planning on using it to react to the byte `s'

Answer 32:

As the course notes say, polling should only be used as a last resort. I wonder, however, if you're actually polling.. Polling code is specifically this:

    PRI ALT
      c ? x
        ...  do something with `x'
      TRUE & SKIP                -- skip guard
        SKIP                         -- do nothing

When executed, if data is available on the `c' channel (i.e. the corresponding outputting process is blocked in the output), then that data will be accepted immediately (placed in `x') and the guarded process runs. If data is not available on the `c' channel, the `SKIP' guard is selected and does nothing -- so the `PRI ALT' finishes immediately.

That code is polling, and it can create problems.. For example:

    WHILE TRUE
      PRI ALT
        c ? x
          ...  do something with `x'
        TRUE & SKIP
          SKIP

This code will consume as much CPU as it can until some data arrives on the channel `c'. Of course, the correct code in this case (since the process does not interact with anything else in the loop) would be:

    WHILE TRUE
      SEQ
        c ? x
        ...  do something with `x'

This code, on the other hand, will wait for something to arrive on `c' then do something with the data received. And waiting (either blocked on channel communication or waiting for a timeout with `AFTER') does not consume the CPU. (although busy-wait versions of these could be created easily, it would be daft..).

It's the `SKIP' guard in the `PRI ALT' (and subsequent do-nothing process or do-very-little process) that constitutes polling.

The following code, for example, is not strictly polling (but it is not nice code):

    WHILE TRUE
      PRI ALT
        c ? x
          ...  do something with `x'
        TRUE & SKIP
          SEQ
            d ? y
            ...  do something with `y'

If you've written stuff like that, you probably wanted instead to write:

    WHILE TRUE
      PRI ALT
        c ? x
          ...  do something with `x'
        d ? y
          ...  do something with `y'

These two code fragments do not behave in the same way, however. The first will commit to input on `d' if `c' is not ready -- refusing then to service `c' until something has arrived on `d'. The second will happily wait for both, and service the first channel that becomes ready (or `c' in preferance to `d' if both are ready).

You can read some more on ALTs and polling in this occam tutorial.

Keywords: q4 , polling

Referrers: Question 23 (2010)


Question 33:

I was reading the bit about graceful termination in the course notes and understand about sending poison down the line to shut each process down properly. My question is does this mean that we have to change every single component that we use, i.e. `delta', `succ', etc. ?

Answer 33:

Yes, to get processes like `delta' to shut down nicely, modification will be required. However, you're not expected to implement graceful termination for Q4 -- you can do if you like, but it's quite a lot of hard work. Essentially anything that has a `WHILE TRUE' loop needs adjusting in some way -- such loops cannot terminate..

Keywords: q4 , graceful-termination


Question 34:

When the system is paused, do we need to guard against the user typing in other valid command letters such as `n', `p' etc. ? In my system, when it is paused through a `s' pressing any other valid commands creates a deadlock!

Answer 34:

From the `q4.occ' file:

-->  's' ==> suspends output to the screen.  Output is resumed by the next
-->          keypress (which is NOT processed according to the above rules
-->          -- it is merely the signal to resume output).

So pressing any key whilst paused (including valid command keys) should just resume the output.

Keywords: q4


Question 35:

Hi, how do you import a function like `integrate' from another package ? I.e. how do you call `integrate' in `demo_cycles.occ', to be used within Q2 ? Do we copy and paste it in, or can it be called upon ?

Answer 35:

These PROCs are part of `course.lib' and they become available with the line:

    #USE "course.lib"

One way to find out, of course, is just to try and compile something that uses `integrate' -- the compiler will produce an error if it hasn't been defined (either locally of via `#USE' or `#INCLUDE').

Keywords: course-library


Question 36:

I've completed q4 - but just testing it I've found that my implementation for pairs resetting is a bit odd.

If left on its own the program runs fine and loops round every 20 secs or so. If i press `p' I start to see the list of natural numbers - but the program then crashes at 65535. Is this ok?

Answer 36:

Yes, that's not too serious -- but the crashing is a pain and easily fixed.

The `pairs' process, when subtracting, behaves like `differentiate' (except that it loses the first value communicated -- because of the `tail'). Thus you'd expect to see natural numbers -- or at least the input to the (`integrate' -> `differentiate') part of the pipeline.

Your program crashes when your resttable `pairs' process is reset, because your code uses (I strongly suspect) either a `+' symbol (instead of a `PLUS', which wraps round on overflow without crashing) or a `-' symbol (instead of a `MINUS', which also wraps round on overflow without crashing). The course library `plus' process uses a `PLUS', precisely so that it can be used on number streams that get too large or too small.

Your program `crashing' is expected behaviour, if you have used the algebraic operator symbols. The sum of 1..65535 is just less than 231 -- when 65536 is added, it'll overflow. "Crash" is perhaps a slightly strong term in this case -- the (overflow) error was correctly detected and appropriate action taken. But use the `PLUS' (or `MINUS') operators and the overflow will be ignored -- that's what Java does anyway!

Keywords: q4


Question 37:

I am trying to run programs from the answers folder in \\raptor\files\courses\co516\answers, but from the Unix system I can't seam to get there. On the comand line after typing the "ls" comand I get (understanding that I'm now in the "\\raptor\files\home" folder):

    raptor$ ls
    bluej        core         Desktop          Work documents
    raptor$

and typing

    raptor$ cd ..

to get to "\\raptor\files" dosen't seam to work. Using the "ls" comand I get a list of users in the system. "cd"-ing to my username just gets me back to "\\raptor\files\home"!

    raptor$ ls
    aa206          cr49           jg38           mjf27          rjb7
    :
    .  (a lot more users)
    raptor$

What I want to know is how to get to the "\\raptor\files\courses\co516\answers" folder in Unix.

Answer 37:

The Unix file-system starts at "/", and everything else hangs off it. The "\\raptor\files\" style of path naming is very much Windows-specific. Files on raptor are visible from Windows by means of `Samba' -- some software that understands the SMB protocol. The point is that there is no director "\files\" on raptor -- this is generated magically by Samba (clearly not everyone can have the same home-directory!).

The actual Unix path of your home-directory is "/home/cut/login/". The handy Unix command "pwd" will tell you which directory you're in. The Unix path of the model answers is "/usr/local/courses/co516/answers/", so to get there you'd type:

    raptor$ cd /usr/local/courses/co516/answers
    raptor$

from which "ls" should produce something more meaningful (ie, the model answers).

I find it very handy to have the directory I'm in displayed in the command-prompt. To do this, edit your "~/.bash_profile" file (where the tilde (~) means your home-directory), and add the line:

    PS1='\h:\w:$?$ '

(at the end of the file would be sensible). This particular rune will give you a prompt that looks like:

    raptor:/home/cur/frmb:0$

The path to your home directory will often be shortened to `~', so you might see stuff like:

    raptor:~:0$

instead of the full path. The zero in that lot is generated by the `$?' bit -- this shell variable gives the result of the last executed command, which can be very handy to tell whether something succeeded (and exits with zero), or failed (and exits with non-zero).

Keywords: unix


Question 38:

I am trying to set up a reset for pairs. Where do you best suggest I have replace? Before the input or after? Or can I have more than one replace in a process?

Answer 38:

Yes, you can have as many replace processes as you like in any process network (such as the one needed for pairs.reset). Actually, you should add no replace processes there -- they offer no help in implementing the required change in behaviour of pairs.reset when a reset signal arrives.

Keywords: q4


Question 39:

I'm struggling with the `monitor' method: checking previous anonymous Q+A's I found a student starting the method this way:

    PROC monitor ([]CHAN OF INT out, CHAN OF BYTE keyboard, intr)
      --{{{  forever
      WHILE TRUE
        ...  wait for `intr' and process accordingly
      --}}}
    :

while I have done it this way:

    PROC monitor (CHAN OF INT keybrd, num , int , prs)
      PAR
        id(keybrd, num)
        id(keybrd, int)
        id(keybrd, prs)
    :

I'm totally sure my own version is wrong, what I don't understand is what I'm meant to do exactly for this method; and also I would have thought the input for keyboard would have been a string for "s" "n" etc.. so you can compare which one to reset. I have done the methods for `numbers.reset', `integrate' and `pairs' and they're working. I'm not sure where to proceed from here though.

PLEASE HELP!!!! :'(

Answer 39:

Going from your last paragraph, keyboard input is characters -- that are represented by BYTEs in occam. occam doesn't have a native `string' type like Java, so that rules that out. Strings in occam are done using arrays of BYTEs.

What you suggest is largely sensible (and correct): wait for some input from the keyboard, then compare to decide which component to reset. The first code fragment above is on the way to doing this. The second code fragment isn't; this will fail to compile due to the parallel inputs on "keybrd" -- also it's unclear what such code should do: relay the values on "keybrd" to each of the three reset-able processes ? Better to do the input first, then decide what to do with it.

Just as a point to convention: occam PROCs should be called "processes" or "procedures", not "methods" (a term from OO programming, which occam isn't). occam also has FUNCTIONs (that return values) and these are very different from PROCs (non-value parameters can be used to "return" data from PROCs, however).

Keywords: q4


Question 40:

Can I access kroc and exceed from parkwood ? If yes, how do I access them ?

Answer 40:

Yes, you can do this. It should simply be a case of installing eXceed then launching the "CS Unix Hosts" icon (which is an eXceed session file). You can install eXceed from `\\corfe\install\' or `\\corfe\packages\' (iirc). Failing that ask on the newsgroups; I'm sure lots of people have done this successfully before.

Keywords: unix , exceed

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.