XML

kent logo

CO538 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 tagged-protocol

2006

Question 107 (2006):

Submission reference: IN1196

Is it possible to put a guard on a variant protocol? TRUE & in ? CASE or TRUE & poison doesn't seem to work.

Answer 107:

Yes, but only if that precondition is part of an ALT. You can't selectively precondition against individual cases – that would require the outputting process to first check the inputting process's ability to handle the particular case, which is not supported. Examples of things which do work are:

  ALT
    cond & in ? CASE
      INT x:
      first; x
        P (x)
      second
        Q ()
    INT x:
    cond2 & in ? CASE first; x
      P (x)

Note: the last guarded process above needs explaining. It could have been written:

    cond2 & in ? CASE
      INT x:
      first; x
        P (x)

It's just that if we only have to deal with one of the variants (e.g. under condition cond2 above), we can write out that variant on the same line as the CASE input. It's just a syntactic shorthand, saving one line of code. It's part of the language, but I don't usually bother with it (and never showed it to you).

Keywords: tagged-protocol , alternation

2004

Question 73 (2004):

This may sound silly but there are no questions about using "CASE", could you please tell me a bit more about it and when it's used please. Thanks.

Answer 73:

The "CASE" construct is much like C and Java's "switch". In occam, "CASE" can be used in three places: as a "switch" on some variable/expression; in tagged protocol definitions; and in tagged protocol input. There are plenty of examples of "CASE" usage -- see the past questions, course notes, the model answer to Q4 (its "keys" process) and this occam tutorial. It would also be neater to use a "CASE" for examining the result of a "compare.string" function, rather than an "IF", in Q6.

Keywords: tagged-protocol , case , q4 , q6


Question 72 (2004):

Concerning q6, we are required to compare two names -- one of which will be passed in through the "in" channel of a particular cell and the cell will itself contain the other.

In order to reference the incoming name, I understand that some temporary variables need to be used along with pattern matching in order to get the actual name from the "NAME.NUMBER" protocol.

I am having trouble referencing the name within the current cell to compare with this... do we need to create other procedures to separate out the components of "NAME.NUMBER" and to write back to them or is there a better way?

Answer 72:

The whole point of a protocol structure such as NAME.NUMBER is that it presents its components to you very simply. There is absolutely no need to write procedures to separate them out ... that makes no sense ... they are already separated! Look at the code in display to see how to input the components into separate variables. The language does not allow you to input them into anything else (e.g. some structure from which you have to separate things).

You don't need any clever pattern matching! You just need the equal.string function, which is documented in your q6.occ starter file (and the "libsrc" course library directory) and has been explained in your seminar groups. Some, of course, will use the compare.string function instead (for producing a sorted list of collated names and marks).

Keywords: q6 , tagged-protocol

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