
This posting is for *information* only - i.e. there is nothing in here
that is examinable.  Using records *may* help in answering Q6 ... but
there is a better answer that does not use them ...


			 =================
                         OCCAM 2.1 RECORDS
			 =================


Anyone wanting to know how to declare data types, including records,
should look at:

  http://www.hensa.ac.uk/parallel/occam/documentation/

and follow the link "occam2.1 language extensions since occam 2".

Basically, you can declare new types:

  DATA TYPE COLOUR IS INT:

The type COLOUR is *different* to INT.  So you can't:

  INT p:
  COLOUR q:
  SEQ
    ...
    p := q          -- won't compile since the types don't match
    ...

This provides lots of extra security when well used.

To define a record type:

  DATA TYPE THING
    RECORD
      INT size, weight:
      COLOUR colour:
      REAL64 frequency:
      [255]BYTE name:
  :

This gives you a record with 5 fields - two INT ones, one COLOUR,
one REAL64 and one BYTE array (e.g. a string).
Then you can declare variables of this new type:

  THING x, y, z:
  [42]THING database:

These data types are first class types.  You can assign them to
each other or send them down channels:

  CHAN OF THING c:

  PAR
    
    THING x:
    SEQ
      ...
      c ! x
    
    THING y, z:
    SEQ
      ...
      c ? y
      z := y
      ...

To access individual fields of a record, the notation is like array
indexing:

  THING x:
  COLOUR c:
  REAL64 a:
  SEQ
    ...  set up X
    ...
    c := X[colour]                 -- types must match
    a := X[frequency]              -- types must match
    ...

You can initialise (or reset) a whole record in one go:

  VAL COLOUR green IS 3:

  THING x:
  SEQ
    ...
    x := [42, 180, green, 33.333, "Thomas ..."]
    ...


REMINDER: this is for interest only -- it's not examinable ... have fun!


Peter Welch.
