XML

kent logo

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 q2

2003

Question 7 (2003):

In the method `tabulate.int' from q2.occ, how does the sequence:

    SEQ
      in ? n
      out.int (n, 15, out)
      out.string ("*c*n", 0, out)

work ?

I'm curious because I'd like to make a:

    PROC testing (CHAN OF BYTE in, CHAN OF INT out)

procedure/method for testing purposes. In other words, how does the conversion work and is it basically the same to convert the other way around?

Answer 7:

The conversion from an `INT' value to the sequence of decimal digits that represents it is performed inside `out.int'. Essentially it involves a sequence of `modulo 10' then `divide-by 10', until the value is zero. It's mildly more complicated since the digits are generated in the reverse order.

The code for `out.int' can be found on raptor in:

    /usr/local/courses/co516/libsrc/utils.occ

Converting the other way is, as you suspect, largely the reverse. However, it's already been programmed for you (also in `utils.occ'):

    PROC ask.int (VAL []BYTE prompt, INT n, VAL INT max, CHAN OF BYTE in, out)

As an example, your `testing' PROC can be implemented with:

    PROC testing (CHAN OF BYTE in, out, CHAN OF INT vals.out)
      WHILE TRUE
        INT n:
        SEQ
          ask.int ("Enter a number: ", n, 11, in, out)
          vals.out ! n
    :

The `in' and `out' channels should be wired to the keyboard and screen respectively. The screen channel is needed so that characters can be echo'd as typed, in addition to displaying the prompt. `ask.int' handles all the unpleasantness of keyboard input, such as rejecting invalid characters and handling backspace properly.

The `max' parameter specifies the maximum number of digits that may be entered, inclusive of any leading `+' or `-'.

Keywords: q2 , output , conversion


Question 5 (2003):

How do we submit the occam coursework due in next week ?

Answer 5:

You should print out your code and submit it with a cover-sheet to CAS reception. Remember also to include a network diagram of your `differentiate' process. You can do the diagram in ASCII-art, print it separately, or hand-draw it (neatly, please!).

Keywords: q2 , submission


Question 4 (2003):

In question 2 we display the numbers on the screen. Trouble is that the numbers go too fast and end up giving a fatal error. Is their a way, or a command, to show a window's worth and than wait for you to push a button. Also, what output should we be getting from numbers anyway.

Answer 4:

You can pipe the output through "more", e.g.

    ./q2 | more

Hitting the space bar will give you another screenful of output. Pressing `control-c' will interrupt it, but that leaves the terminal in a funny state, with echoing turned off. Type (blind)

    stty sane

to restore sanity.

The fatal error that occurs is usually integer overflow. Don't worry too much about this yet, but in general, it is an important consideration for software systems. Integer overflow in question 2 ought not to happen until a significant number of values have been input. If it overflows early, there's probably a problem with your code/network.

The `numbers' process generates the sequence `0, 1, 2, 3, 4, ...', forever. After being sent through `integrate' and your `differentiate', you should get the same sequence (0, 1, 2, 3, ...).

There are executable answers in `/usr/local/courses/co516/answers' on raptor, for all 7 questions.

Keywords: fast-output , q2

Referrers: Question 6 (2003)


Question 3 (2003):

I seem to have some problems when I run q1.occ and q2.occ. They both compile but when i run them I get:

    Program deadlock: no process to run.

What am I doing wrong ?

Answer 3:

This generally means that your program deadlocked before anything useful happened. A common error is mis-construction of the top-level process, using `SEQ' instead of `PAR'.

If you have access to KRoC on a Linux system, compile the program with the `-d' flag (debugging). When the system deadlocks, it will report the location (in the source file(s)) of deadlocked processes, e.g.:

linux$ kroc -d q1.occ -lcourse
kroc: Selecting post-mortem debugging
Warning-oc-q1.occ(40)- Parameter error is not used
Warning-oc-q1.occ(40)- Parameter keyboard is not used

linux$ ./q1
KRoC: Deadlock:

  Instruction "OUTWORD"
    in PROC "A"
    in file "q1.occ"
    near line 29

In this case, the system deadlocked with the `A' PROC trying to perform an output (line 29 in this particular q1.occ). Note that this will not work with the version of KRoC on raptor. It will, however, work on gonzo.

Keywords: q2 , deadlock

2001

Question 4 (2001):

When is our first assignment (q2.occ) due?

Answer 4:

A hard-copy listing of your source code should be handed in to the CAS office by close of service (around 4pm) on Thursday, 8th. November, 2001. Cover sheets will be made available next week.

Note: remember that your differentiate process should be implemented in the same style as the implementation of integrate -- i.e. as a network of simple components of the level of those in the demo_cycles.occ library (see slides 5-3 and 5-8). This requirement is made in the comments in your q2.occ starter file. A solution for differentiate in the form of a single serial process will get a maximum of 6 out of 10. [See also the Hint: given in those comments.]

Note: you must include network diagrams of your differentiate and q2 processes (the latter contains your test rig). These can be hand-drawn neatly on your hard-copy listing or machine-drawn on other paper and stapled to your listing. The diagrams should be annotated with process/channel names that correspond to those used in your code. Channels should be arrowed to show the direction of data-flow. Also, think carefully about the icon you choose to represent the minus component. Unlike plus, minus is not symmetric over its input channels and your icon must reflect this. When looking at its use in a network diagram, we must be able to tell which channel numbers are being subtracted from which.

Note: your source code must be adequately (but not over-) commented, should use meaningful variable names and be well laid out. Of course, you have no choice in indentation layout (;-), but spacing within lines and between them (e.g. between PROC declarations) helps readability (and marking!).

Note: comments in occam source code are introduced by two dashes, --, and include everything following this symbol to the end of the line. [This works like // in Java.]

Keywords: q2 , diagrams , comments

Referrers: Question 6 (2001) , Question 6 (2001) , Question 12 (2001)


Question 2 (2001):

Hi, I have completed the first assesed exercies question 2. However, the minus I made to do it is a little weird. It has two input channels and two output channels - is this a problem? Does it matter what it looks like or is it fine as long as it works?

Answer 2:

Your minus sounds weird indeed! "As long as it works ..." is never good enough though. Solutions must work and it must be easy to see how they work. So, as long as you document clearly what your two-output minus does and how this helps solve the question, that will be fine.

Keywords: q2

2000

Question 15 (2000):

Please could you tell me who, and where, do we submit this assignment (q2) to?

Answer 15:

As explained in the seminars, you must submit hard copy listing plus diagrams (see answer to Question 14 (2000)), attached to a cover sheet, to the CAS office by their close of business this Thursday (9th. November). Cover sheets were given out during seminars or may be obtained from the Co516 pigeon hole near CAS reception.

Keywords: q2 , submission


Question 14 (2000):

I have completed q2.occ and as far as I can make out, it works!!!

My class supervisor said we had to produce 2 chip diagrams to hand in as part of our assignment. Am I right in thinking they are:

Is there any particular program I should use to create the diagrams? I done them in Word, using the flowchart symbols, but it don't look that great.

Also, how do I print my source code from Origami on a public PC????

Answer 14:

Yes to your first question - you do have to submit these two diagrams as well as your code listing.

No to your second question - the quickest thing is simply to draw them neatly by hand on your listing (next to the occam code that implements each diagram).

Origami doesn't have a print command. The files it produces are, of course, plain text. So you could pick up q2.occ (say) in a Windows editor (e.g. PFE) and print from there. Or you can print the file directly from Unix.

To help with the latter, there are two commands (pt and pq) in the etc directory in the course area:

  /usr/local/work/co516/etc/pt
  /usr/local/work/co516/etc/pq

If you haven't already done so, make a bin directory in your home directory and copy the above files over to it:

  mkdir ~/bin
  cp /usr/local/work/co516/etc/p* ~/bin

Then, set this ~/bin directory to be the first item in your path environment variable. This can be done by editing the definition of that variable in the .cshrc file in your home directory (if you are using the C-shell) or the .bash_profile file in your home directory (if you are using bash). If your unix command prompt ends with %, then you are using C-shell - if it ends in $, you are using bash. The syntax of how to set these environment variables is different for the different shells - but you can work it out from how they are already defined.

Once the above has been done, to print a file (say q2.occ) to a printer (say myprinter), the command is:

  pt q2.occ myprinter

To inspect the print-queue on a printer (say myprinter), the command is:

  pq myprinter

Keywords: diagrams , q2 , printing

Referrers: Question 15 (2000)


Question 13 (2000):

I am doing q2. When I run it I can't tell if it is working properly because once I break, I can't scroll up and see whether the 0 appears in the output. Is there any way of dumping my ouput to a file so I can see it all?

Answer 13:

The simplest answer is to get a scroll bar - see the answer to Question 9 (2000) to find out how to get one.

It is possible to redirect your output to a file - but, in this case, that's not a good idea since the output is infinite and you will flood the disc!

Simpler is to pipe your output through the Unix more utility:

  q2 | more

Now, you only get a screenful at a time. Press carriage-return to see one more line or space for a further screenful. To end your program, type ctl-C. Warning: do not type q to quit the more program. That sends a broken pipe signal to the occam process which doesn't handle it properly. Your occam program will exit but not reset keyboard input to echo mode. That means that you get back to the Unix prompt and type in commands ... but you won't see those commands. To restore things to normal, type in (blindly!):

  stty sane

and you will now be able to see what you type again.

An alternative to all this is to slow down the output so that you can read it! For example, put in a tenth of a second delay after printing each output line. Then, only 10 lines per second will be displayed and you will have time to check if your output sequence starts with a zero. One way to do this is to modify the tabulate.int (see the latest version of q2.occ) as follows:

  PROC tabulate.int (CHAN OF INT in, CHAN OF BYTE out)
    WHILE TRUE
      INT n:
      SEQ
        in ? n
        out.int (n, 15, out)
        out.string ("*c*n", 0, out)
        --{{{  delay 100 milliseconds
        TIMER tim:
        VAL INT milliseconds IS 1000:    -- TIMERs measure microseconds
        INT t:
        SEQ
          tim ? t
          tim ? AFTER t PLUS 100*milliseconds
        --}}}
  :

Keywords: q2 , output

Referrers: Question 24 (2003) , Question 7 (2001)


Question 11 (2000):

We were told in our class that there is a process called minus that we can use in answering question 2. If this is the case, then where is the process as it's not in demo_nets or demo_cycles? If this is not true, then can we make up process called minus?

Answer 11:

You must have mis-heard. There is no process called minus in the course library. For question 2, you must make up your own - use the process called plus, which is in the library (in demo_cycles) and which was presented in today's lecture (slide 5-5), as a model.

Keywords: q2

Valid CSS!

Valid XHTML 1.0!

Last modified Mon May 15 17:39:47 2006
This document is maintained by Fred Barnes, to whom any comments and corrections should be addressed.