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 seq

2000

Question 1 (2000):

What *exactly* does SEQ do and when is it *not* necessary?

Answer 1:

occam lets us write parallel code with the same fluency as it (and other languages) lets us write sequential code. So, whenever we have a collection of statements, we have to say whether they are to be executed in SEQuence (in the order written) or in PARallel (in which case, the order written is irrelevant). For example, the statements:

    in ? n           -- input from channel, in, to variable, n
    a := 2*n         -- multiply n by 2 and assign the answer to a

only make sense for SEQuential execution. The way we specify SEQuential execution is to indent them as the body of a SEQ construct:

  SEQ
    in ? n           -- input from channel, in, to variable, n
    a := 2*n         -- multiply n by 2 and assign the answer to a

On the other hand, the following statements:

    in ? n           -- input from channel, in, to variable, n
    a := 2*b         -- multiply b by 2 and assign the answer to a

are logically independent from each other. In this case, we can choose whether to have them executed in SEQuence (as above) or in PARallel:

  PAR
    in ? n           -- input from channel, in, to variable, n
    a := 2*b         -- multiply b by 2 and assign the answer to a

Aside: occam does not allow us to specify PARallel execution of statements that interfere with each other's variables (or channels) - these rules are made precise in section 4.2 of the occam2.1 Checklist. So, the construct:

  PAR
    in ? n           -- input from channel, in, to variable, n
    a := 2*n         -- multiply n by 2 and assign the answer to a

would be rejected by the compiler.

Note: the statements controlled by a SEQ (or a PAR) must be indented by two spaces. There can, of course, be any number of statements -- not just two as in the above examples. The end of the construct is indicated by outdenting back to the level of the controlling SEQ (or PAR).

Keywords: seq , sequential-execution

Referrers: Question 28 (2003) , Question 56 (2003) , Question 3 (2000) , Question 28 (2000)

Valid CSS!

Valid XHTML 1.0!

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