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 protocol

2004

Question 108 (2004):

I'm thinking of changing my protocol from:

    PROTOCOL REPORT
      CASE
        thinking
        hungry
        ...
    :

to:

    PROTOCOL REPORT
      CASE
        thinking; INT
        hungry: INT
        ...
    :

to tell me which philisopher is hungry, thinking, etc. Is this a wise move or is there another way I can find this out in the "display" process ? Currently I'm ALTing over the channels to see if they're thinking, hungry, etc.

Currently if a philisopher is thinking it prints (philosopher is thinking) with no knowledge of who is thinking.

Answer 108:

Yes, this probably is a wise move. The only other way you can get that information is by having the "display" process knowledgeable about its wiring. I.e., in the array of "REPORT" channels, which channel is connected to which philosopher, etc. This is not entirely desirable, however, since re-wiring such a network would break the "display" process.

Keywords: q7 , protocol


Question 64 (2004):

Two questions in one here. First of all waht is a counted array?

Second currentley I am trying to create a cell for q6. All I am trying to do at the moment is read in the protocol then just output what ever comes in. So just like the ID in the lego.occ. Looking at Fred's Occam tutorial as the protocol is a tagged-protocol I need to do something like:

    PROC cell(CHAN OF NAME.NUMBER in, out)
      in ? case
        string; INT::[]BYTE; INT
          ...  do something
        poison
          ...  do something else
    :

How do I read in the "string; INT::[]BYTE; INT" and the "poison" into a varible.

Answer 64:

First question: section 7.4 of the "occam2 Checklist". Also, slides 5-45 through 5-47.

Second question: section 7.3 of the "occam2 Checklist". Also, slides 10-18 through 10-21 (in the Powerpoint Chapter 10, these are currently slides 20 through 25).

Please look through your notes before asking questions here!

Keywords: protocol , q6


Question 54 (2004):

How can I make a simple routine that forwards data of `NAME.NUMBER' ? I'm trying:

    SEQ
      INT size:
      in ? size::n; m
      out ! size::n; m

And have also tried:

    SEQ
      INT size:
      in ? string; size::n; m
      out ! string; size::n; m

But I'm getting errors such as "string is not delcared" and "Simple input is not allowed on a channel with a tagged protocol".

I have looked over the chapter 10 pages, but it doesn't cover protocol input for just one type of input. I assume you don't need to use another CASE here.

Answer 54:

The first problem is the scope of `size'. See the answers to Question 19 (2004), Question 29 (2000) and Question 3 (2000).

As for the tagged-protocol input, why do you `assume you don't need to use another CASE here'? Slide 10-21 in the printed notes (chapter 10, slide 25, in the Powerpoint) and section 7.2 of the "occam2 Checklist" show you the syntax for this:

    in ? CASE
      INT size:
      string; size::n; m
	out ! string; size::n; m

If you don't specify the `poison' case, that's fine ... but if a `poison' arrives, your process will STOP (i.e. crash!).

So, the above is what the code fragments in your question should have been, assuming that your variables `n' and `m' have also been defined somewhere (e.g. just before or after your `size' declaration). However, this code fragment only forwards `string' variants of the `NAME.NUMBER' protocol -- not all data variants as the wording in your question implies. In your solution to Q6, you will need to be handling all variants of `NAME.NUMBER'.

However, here's another bit of occam. When inputting a `CASE' protocol, if you are sure that only one variant message will arrive, there is a special syntax ... but you still have the `CASE' keyword and the relevant tag name. For your example, the shortcut code would have been:

    INT size:
    SEQ
      in ? CASE string; size::n; m
      out ! string; size::n; m

though it's not actually any shorter (because of the need for the `SEQ')!

Keywords: q6 , protocol

2003

Question 59 (2003):

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 58 (2003):

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 57 (2003):

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 53 (2003):

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)

2002

Question 34 (2002):

This is part of my display proc which reads in the reports from philosophers and prints the relevant thing:

  ALT i = 0 FOR 10
    in[i] ? CASE
      thinking
        ...
      sitting
        ...
      ...  etc.

and this is some of my protocol:

  PROTOCOL report
    CASE
      thinking; INT
      sitting; INT
      ...etc...

I'm getting the error:

  Error-oc-q7.occ(132)- Not enough items in i/o list

is this something to do with the type of ALT I am using or the protocol?

Answer 34:

Your ALT is wrong - the protocol looks OK. As the error message says, you have not supplied enough items in your i/o lists. For instance, to match the pattern defined by your thinking tag, you must follow the tag with an INT variable:

  ALT i = 0 FOR 10
    INT index:
    in[i] ? CASE
      thinking; index
        ...
      sitting; index
        ...
      ...  etc.

Keywords: protocol


Question 26 (2002):

I get this funky error and don't know what it means and how to solve it. Any tips would be appreciated.

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

It happened when I tried to store a NAME.NUMBER using:

  in ? nameTemp; scoreTemp

Answer 26:

NAME.NUMBER is a tagged - sometimes called a CASE or variant - protocol. See slide 10-21, section 7.3 of the Checklist paper or the display process in q6.occ, for how to input from a channel carrying such protocool. It should be somelthing like:

  in ? CASE
    ...  local delarations
    string; length::nameTemp; scoreTemp
      ...  response to name-mark code
    poison
      ...  response to poison code

Keywords: q6 , protocol

Referrers: Question 53 (2003) , Question 27 (2002)

2001

Question 18 (2001):

I keep getting the error:

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

when I just try to connect the collate process between the read.data and display in Q6. What do you think I should do?

Answer 18:

You should not try to do simple input on a channel with a tagged protocol! Tagged (or CASE) protocols are explained in Section 7 of The occam Checklist and in slides 10-18 through 10-22 (which have been talked though in lectures). See also the code in the display process given in your q6.occ started file.

Keywords: protocol , q6

Referrers: Question 53 (2003)

2000

Question 87 (2000):

The following code:

  PROC displaying ([]CHAN OF DISPLAY d, ...)
    WHILE TRUE
      ALT i = 0 FOR 6
        d[i] ? CASE
          thinking
            out.string ("Philosopher is thinking", 25, out)
          hungry
            out.string ("Philosopher is hungry", 25, out)
          ...  etc.

keeps giving me the error:

    Not enough items in i/o list.

Why does it do that?

Answer 87:

Because there are not enough items in your i/o list. Your DISPLAY protocol must contain variants that contain something other than just a tag name - maybe:

  PROTOCOL DISPLAY
    CASE
      thinking; INT
      hungry; INT
      ...  etc.
  :

In which case, your CASE input must provide the necessary variables for the relevant variant lines. For example:

        d[i] ? CASE
          INT id:
          thinking; id
            ...  make the report
          INT id:
          hungry; id
            ...  make the report
          ...  etc.

Keywords: q7 , protocol

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.