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:

Submission reference: IN1820

For the speed and freeze print control processes, should these go before print.streams in the network, or could we put them between print.streams and the screen? If the former, could you explain (or point to) how to pass []CHANs to a process?

Answer 21:

It can be done both ways, but the simplest is to put freeze.control on one of the lines, before print.streams.

freeze.control only needs a single channel coming in and going out. It is print.streams that takes the array of channels. Your q4 process just has to declare an array of channels and plug the input end (which is the name of the channel array, followed by '?') of the entire array into print.streams.

Question 22:

Submission reference: IN1821

I'm trying to do assessment 3. I'm having a problem with the print.streams process. I'm getting an error: "Error-occ21-q4.occ(438)- not enough actual parameters in call of print.streams". I copied the code from PROC demo in course.module and it gives me the same error.

  PROC demo (CHAN BYTE keyboard?, screen!, error!)
     [4] CHAN INT c:
        numbers (c[0]!)
        squares (c[1]!)
        fibonacci (c[2]!)
        times (c[3]!)
        print.streams (100000, c?, screen!)    -- max output: 10 lines per second

Why would this process give me such an error?

Answer 22:

So long as you are using the copy of print.streams that was provided to you in the q4.occ starter file, your print.streams process should accept three parameters: a VAL INT for the delay, an input channel end and an output channel end.

Your solution to q4 should not involve the demo process, only modified versions (with reset lines) of its sub-components with the main network setup in the q4 process itself.

Question 23:

Submission reference: IN1823

Is it okay to use SKIP guards for PRI ALTs in q4?

Answer 23:

Yes, if needed.

Question 24:

Submission reference: IN1824

When you mention speeds in lines per second,obviously those speeds are very hard to guarantee exactly. Should we just roughly guess that we should pause the thread of execution so that it doesn't exceed 32 lines per second as the minimum and 256 as the maximum?

This also seems very fast. Should the values not be lower?

Answer 24:

No, your code should make best efforts to output at the line rate specified (by doubling and halving speeds interactively). The question states that the minimum line rate is 1 line per second, so you may wish to re-read this section carefully.

Question 25:

Submission reference: IN1822

For pairs2, could we use some kind of process that turns a number into a negative and add this, i.e, instead of 3+6, we have 6+(-3)? Or am I barking up the wrong tree here?

Answer 25:

No, this is the best way to solve this problem.

Question 26:

Submission reference: IN1827

For people who liked the caramel waffles given to us in our seminar you'll find similar ones at Lidl in packs of 10 (bigger than the little ones we got too !)

Thought some of you would like to know.

Answer 26:

Glad you enjoyed the waffles and thanks for the tip on locating them locally in the UK.

Keywords: waffles

Question 27:

Submission reference: IN1825

I'm working on the speed control on q4 and I'm getting some very strange behaviour, whenever I use the pause process, regardless of what value I pass it to delay by, it always seems to delay by approx 1 second, whether I set the delay value to 1, 10, 100, 1000, 10000 or any other number in between. And when my speed control changes the delay value, I can't see the result since it just insists on printing at that constant rate of about one line per second.

If I remove the pause completely, it outputs several thousand a second (since print.streams is initialised to -1).

Any idea why this might be happening? I'm in panic mode right now!

Answer 27:

Sorry – you submitted this with just over an hour to the deadline ... which was a bit late for us to respond! In any case, without seeing your code, there's not enough info to suggest what's wrong ... and we wouldn't let you post full implementations of things like speed control and ask why it doesn't work (see paragraphs at the top of each anon Q&A page).

Make sure you get good feedback from whoever marks your submission! Complain if you don't ...

Keywords: q4

Question 28:

Submission reference: IN1826

Would it be possible for example solutions to be given for assessments which have been closed so we could see more ideals answers if our code was messy or not as clean as it could be?

Answer 28:

Model answers for exercises 1 through 4 and for the extra exercise 1 are available – details in the "Week 7" and "Assessments" boxes on the Co538 moodle page.

Question 29:

Submission reference: IN1828

I've added the following output channel to the philosopher: CHAN PHIL.STATE report! PHIL.STATE has been defined as a CASE protocol. secure.college outputs an array of this particular protocol type to the display method. This is defined in the secure.college header like so:

    CHAN [n.philosophers]PHIL.STATE phil.out!

However, when attempting to assign each philosopher in the replicated PAR to a particular point in this array I get an error: "phil.out subscripted too many times". I am assigning it as follows:

    philosopher (i, left[i]!, right[i]!, down[i]!, up[i]!, phil.out[i]!)

What does this error mean? Am I doing something completely wrong?

Answer 29:

Your declaration of the channel array phil.out is wrong. You have declared a single channel that carries an array of PHIL.STATE messages (in each message):

    CHAN [n.philosophers]PHIL.STATE phil.out!

You need an array of channels, each one carrying a single PHIL.STATE in each message:

    [n.philosophers]CHAN PHIL.STATE phil.out!

Now, phil.out[i] references element i from the channel array. Before, phil.out was not an array, so adding the array subscript was an array subscript too many - as the error message says!

But there's something wrong with our compiler! occam-pi currently does not support the concept of an array of PHIL.STATE messages. On encountering your [n.philosophers]PHIL.STATE, the compiler should have thrown an error message of the form:

    Error-oc-charray.occ(line-number)- Name PHIL.STATE is not a TYPE

Investigating ...

Keywords: q7 , arrays , channels

Question 30:

Submission reference: IN1830

Could I clarify that the only use of a shared channel is that you get a free FIFO mechanism for handling requests? As opposed to implementing a FAIR ALT – this doesn't actually exist does it?. Numerous channels per se aren't bad - it's not we are going to run out of channels? Or is it to declutter things?


Answer 30:

A shared channel writing-end means that the writing processes are FIFO queued to do their writing on that channel – which is fair. If the other (reading-)end is not shared, than the single reader there will automatically provide a fair service to all writers.

The above is simpler than having a number of classic channels (with non-shared ends) from all the writers to a single reader, with the reader having to be programmed with fair-alting logic to provide a fair service. There are times when we have to do this though – e.g. when the protocols on the channels have to be different (although this can usually be overcome with variant protocols and variant protocol inheritance) or when fair service for some channels has to be balanced with prioritised service for others.

You are right that occam-pi does not support the notion of FAIR ALT as a language mechanism. That would not actually make sense, since the notion of fairness only is relevant when many executions of the ALT take place. The question of fairness for a single ALT does not arise. If fairness were introduced at the language level, it would have to be in terms of a loop that services a set of channels – e.g.

    FAIR SERVER i = 0 FOR SIZE in?
      in[i] ? x
        ...  deal with x

which would mean something like:

    VAL INT n IS SIZE in?:
    INITIAL INT favourite IS 0:
      PRI ALT i = favourite FOR n
        VAL INT i.mod.n IS i\n:
        in[i.mod.n] ? x
            ...  deal with x
            favourite := i.mod.n + 1   -- channel just serviced become least favoured

where we have used classical fair alting logic (see Question 62 (2007)).

FIFO servicing of channel inputs is not the only benefit of shared channels. The reading ends of channel may also be shared, which provides for fair distribution of messages from a single writer. And both ends of a channel may be shared, which provides a fair brokerage service for putting reader and writer processes in touch.

As you say, numerous channels are not necessarily to be avoided. After all, each one only requires one word of storage (to hold a reference to a waiting partner – or nil if no process is waiting). But if you can replace an array of channels with one shared channel, that does tend to simplify the picture and associated logic.

Keywords: q7 , fair-alt , shared-channel

Question 31:

Submission reference: IN1831

For those of us interested in the Advanced Concurrency course (and won't be here next year in the event it does run again), would it be possible for the material to be made available for us to look through?

Answer 31:

A big chunk of it deals with the mobility mechanisms (for data, channel-ends and processes) of occam-pi. Slides on these are available on the Co538 webpage – called Mobiles.

I'm sure Fred will be making his slides available from the extra lecture next week (see the Week 9 box on the webpage). We'll see what else we can find!

Question 32:

Submission reference: IN1832

Can you please explain why the following is not working? I believe I have followed the rules diligently. Ta.

    PROTOCOL ralph
        rabbit ; INT
        door ; BOOL

    PROC turnkey([]CHAN ralph x, CHAN INT out!)
      INT num:
      BOOL bl:
          [0]x ? CASE
	    rabbit ; num
	      out ! num
          [1]x ? CASE
	    rabbit ; num
	      out ! num
	    door ; bl
	      bl := FALSE	     

Answer 32:

By "not working", you must mean not compiling. As you spotted in your later question:

    > sorry, think I've cracked it, should be: x[0] ? CASE

... the problem is not in your code dealing with the variant protocol – your problem was in referencing array elements.

Yes, occam-pi is a little inconsistent here. When declaring array types, the square brackets come before the array name (unlike, say, in Java). When referencing array elements, the square brackets come after the array name (like, say, in Java).

Question 33:

Submission reference: IN1835

Hi there the kroc compiler is making weird complaints.

    ?????@?????-???????:~/raptor/private/co538/assessment4$ occbuild --program q7.occ
    Fatal-occ21-q7.occ(75)- unknown tag N_SPROTDEF in pi_valcheck

    * The compiler has detected an internal inconsistency.		    *
    * Please email kroc-bugs@kent.ac.uk with a copy of the code which   *
    * broke the compiler, as this is probably a compiler bug.	    *
    * Please include the KRoC version and any other relevant details.   *

    kroc: /usr/local/kroc/bin/occ21 failed to compile q7.occ to q7.tce

What is this complaining about? any ideas how I fix it?

    ...  code removed

Answer 33:

Protocol extension is only allowed between variant (i.e. CASE) protocols. Your line 75 tries to extend report protocols for phils, forks and security – but only the fork reports has variants. Your definitions are easily corrected – change:


to the single-variant:

        security; INT

and similarly for your phils report protocol.

But our compiler shouldn't have blown up! It should give a decent error report. I'll pass on a bug report - thanks.

Keywords: q7 , protocol-inheritance

Question 34:

Submission reference: IN1829

When attempting to assign a background in occade using:

    occade.load.playfield (occade, "images/background.png", 0, 0)

I get the following error:

    STOP error
    The error occured on or around line 41 in rasterio.occ

The occade window loads correctly prior to that statement being made.

Answer 34:

Adam Sampson (ats@kent.ac.uk) writes ...

To load PNG images, you need a KRoC that's been built with support for the libpng library. (You can't do this for the Transterpreter because it relies on CIF – although I think Carl had a fix for that in the LLVM branch?  If you don't know about CIF and LLVM and are curious, come and ask us, :)

But if you have occade working, a quick workaround would be to use images in BMP format instead; SDL has built-in support for loading BMP files, so occade can always do that.

Keywords: q7 , occade

Question 35:

Submission reference: IN1834

I am trying to get random text to scroll in occade. My current method involves creating a sprite and then loading text using a font/image package.

However I want to change this text often. So far I have this methodology:

Before I try and bodge a way of doing this, is there an easy/ier way of doing this?

Also does occam provide a way of pushing a value to an array? Thanks.

Answer 35:

Adam Sampson (ats@kent.ac.uk) writes ...

Sounds like you have it pretty much figured out already. :)

You don't need to create a new sprite each time -- you can just create one sprite, make it visible, then send it the "load.text" message each time you want to change the message it's displaying. The score displays in Parrot Attack work this way, for example.

To insert a character at the start of an array, the easiest way is just to shift everything else up by one -- copy the second-last character over the last, then the third-last over the second-last, and so on. You can do this using a replicated SEQ with the STEP keyword to make it count backwards.

Here's what that looks like as an Occade program:

    #INCLUDE "occade.module"

    PROC demo.text.maker (CHAN BYTE c!)
        SEQ ch = 'a' FOR 26
            c ! BYTE ch             -- the replicator control variable is an INT.
            occade.delay (100000)   -- set whatever speed your display can take.

    PROC display.text (SHARED OCCADE! occade, CHAN BYTE c?)

      VAL INT LEN IS 20:
      INITIAL [LEN]BYTE buf IS [i = 0 FOR LEN | ' ']:
      -- we've not told you about the "array comprehension" syntax above ...
      -- it just constructs an array of size LEN, filled with spaces.

      OCCADE.SPRITE! sprite:


        occade.start.sprite (occade, sprite, -1)
        sprite[req] ! load.text; buf; "images/font10x20.png"
        sprite[req] ! move; 320; 240; TRUE
        sprite[req] ! visible; TRUE

        WHILE TRUE
          BYTE ch:
            -- wait for new byte char to arrive on channel
            c ? ch
            -- add this new byte char to the start of my array
            SEQ i = LEN - 1 FOR LEN - 1 STEP -1
              buf[i] := buf[i - 1]
            buf[0] := ch
            -- update the sprite
            sprite[req] ! load.text; buf; "images/font10x20.png"

    PROC main (CHAN BYTE kbd?, scr!, err!)

      SHARED OCCADE! occade:
      INITIAL OCCADE.PARAMS params IS occade.default.params:


        params[width] := 640
        params[height] := 480
        occade.start (occade, params, "Scrolly text demo")

        CHAN BYTE c:
          demo.text.maker (c!)
          display.text (occade, c?)


Keywords: q7 , occade

Question 36:

Submission reference: IN1836

I've been told that I have to use cursor.x.y to create the interface, however, I don't understand how that would work. Could you explain it to me please? Thanks.

Answer 36:

See slide 14 from these slides and this documentation. You should also look at test-utils.occ from your examples folder and check out the cursor keywords entries in the anonymous Q&As.

Keywords: q7 , cursor

Question 37:

Submission reference: IN1837

What does flushing the screen do?

Answer 37:

Look at the questions under flush in the keyword index (see below for a link), especially Question 91 (2000).

Keywords: flush

Question 38:

Submission reference: IN1838

I want to draw a pentagon made out of '+' as a table for the Philosophers but I don't know how to go about it. How would I deal with the angles accurately?

Answer 38:

You can't - not with an animation made using ASCII characters on a rectangular grid (your terminal window)!

You can only approximate – e.g.

    VAL [][]BYTE pentagon IS ["  ++++++  ",
                              " +      + ",
                              "+        +",
                              " +      + ",
                              "   +  +   "]:

and print that wherever you want it in the scene.

Keywords: q7

Question 39:

Submission reference: IN1839

The coursework in Co538 is probably the most time consuming of all modules, I don't mind I think it's fun, however it seems very unfair that only 20% of the marks are coursework.

Why are there so many marks associated to a few hours long exam when our programming tasks will take us many more hours and probably show more our level of in depth understanding.

It would be nice to get an explanation of your thoughts on this matter. Thanks.

Answer 39:

The aim of the coursework is to let you explore in depth the ideas being presented in the lectures. Without this, any learning you do will be fragile and untested. Doing the coursework lets you discover what you don't understand, since solutions cannot be found without real understanding. Without doing the coursework, you will not discover that you have not understood something and, therefore, will not be able to correct that misunderstanding.

Also, we hope that the coursework will be fun – and are glad that you and finding it so, :). Fun is essential for most things, so we try to make the coursework interesting and fun since we really want you to want to do this work ... because we really want you to understand!

Now, hours! Assuming a 40 hour working week (most of us work much longer!) and 4 modules to study during term, that's 10 hours per week per module. This module has 3 contact hours per week (2 lectures, 1 seminar), so that's 7 hours per week for your own study on this module. Some of that will be spent reading the slides, background papers and talking to / teaching / learning from colleagues. Much of the former will be driven by solving the challenges set out in the coursework. The last two coursework assignments span several weeks (at least three), so it should not be surprising that each may take between 10-15 hours – maybe less, maybe more.

Now, exams! For this module, this is 3 hours work during the exam ... but, of course, an awful lot more in preparation for it. In fact, all the work you spend on your coursework is preparation for your exam. You cannot succeed in your exams without understanding – in depth – the material and, as reasoned above, you cannot do that without the coursework.

Therefore, if the coursework were zero weighted, you would have just as much motivation for doing it. Note that in my definition of the aim of our coursework, the grading of students is not included. Grading is the purpose of the exams, which provides a level playing field for every student in conditions where there is a recorded audit trail of how the work is produced and how it is graded (that can be, if necessary, challenged).

The exam seeks to let the student demonstrate understanding of the concepts and mechanisms presented in the module. It does this by asking for simple explanations and by applying them to solve short problems (that are either hard or impossible to solve without that understanding). The exam does not expect or seek a rote reproduction of material from, say, the course slides. The exam will not penalise trivial mistakes in syntax, say, that would not be made if a compiler were to hand – or, indeed, any material available from the web (e.g. the course slides). It's the ability to explain and apply that is all important. And that is very difficult to achieve without doing the coursework.

Summary: the coursework is there to help you learn, the exam is there for you to show us that you have learnt. It's not just the 20% from your marked coursework that is the achievement of all that coursework. It's the 80% from your exam, which would be near impossible without it.

Keywords: coursework , exams

Question 40:

Submission reference: IN1841

Hi there, I'm having a strange problem trying to pass my shared channel to where it needs to go.

    ...  code omitted

provides me with this error:

    Error-occ21-q7.occ(182)- must CLAIM `reportChan!' before using channels
    skroc: Could not compile q7.occ.
    skroc exited with error code: 1

and I don't understand why. It's more than happy to let me pass reportChan to philosopher and fork. I can delete the security line and it compiles fine. I can't imagine why it insists on me claiming the channel to pass it to security. At no point in my code am I writing to channel yet anyway! Am pulling my hair out. Help much appreciated! Thanks

Answer 40:

There was not enough information in the code fragment you included to answer your question. Also, we cannot reproduce such code fragments (containing too much solution code) in these questions.

However, check that your security guard process declares its reportChan channel as SHARED. Failing that, mail me or your seminar leader your code and repeat your question.

Keywords: q7 , shared-channel

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:22 2013
This document is maintained by Fred Barnes, to whom any comments and corrections should be addressed.