Data Types

Primitive Datatypes

Occam supports five primitive types (Burns, 1988, p. 53):
  1. INT. An integer of length best directly supported by the hardware.
  2. BYTE. A single 8-bit byte for values 0 - 255.
  3. BOOL. Boolean type for values TRUE and FALSE.
  4. CHAN. Communications channel between processes.
  5. TIMER. A special communications channel which produces events after a specified elapsed time.
Various hardware implementations may support a wider variety of primitive types. The transputer, for example, explicitly provides INT16, INT32, and INT64 integer data types, as well as IEEE 754 standard floating point types REAL32 and REAL64 (Burns, 1988).

In occam, variables are declared by listing variable names after a data type. The type declaration list ends with a colon, and must precede the construction (PAR, SEQ, etc.) where the variables are used.

      INT I, J:
      REAL32 X, Y:
      CHAN OF INT Out:
        
      I := 4
      J := 2
      X := .1E+3
      Y := 97123.45              
    


Occam assignments may be listed on a single line, as in the statement:
      X, Y := Y, X    
    

The assignments are executed in parallel, equivalent to the sequence
      PAR
        X = Y
        Y = X         
    
which has the behavior of swapping the values of X and Y. The parallel code is equivalent to the traditional sequential swap operation:
      SEQ
        T = X
        X = Y
        Y = T         
    

Occam supports the general mathematical and boolean operators, with some unique symbol representations that seem unusual today.

AdditionI + J
SubtractionI - J
MultiplicationI * J
DivisionI / J
RemainderI \ J
EqualI = J
Greater ThanI > J     I >= J
Less ThanI < J     I <= J
Not EqualI <> J
Boolean OperatorsAND, OR, NOT
Bitwise ANDI /\ J     (that's / \ )
Bitwise ORI \/ J     (that's \ / )
Bitwise NOT~J
Bitwise XORI >< J

Occam only supports binary and unary expressions! Addition, for example, may only take two operands. To perform addition between three operands, the statement must explicitly include grouping parentheses.


Arrays

Arrays in occam are specified by preceding the type declaration with a size in brackets. Index values start at zero. To enumerate through arrays one element at a time, the SEQ constructor contains a named iterator, which resembles a FOR statement from other languages. An array's size may be determined using the SIZE operator.

The following code first declares a byte array (string) of 7 characters and sends its contents to the output channel. The second segment performs the same action but uses a named constant, Maxlength, to contain the size and the SIZE operator to control the iteration.

      [7]BYTE string:
      SEQ
         string := "Matthew"
         SEQ I = 0 FOR 7
            output ! string[I]      
         
      VAL INT Maxlength IS 7:   
      [Maxlength]BYTE string:
      SEQ
         string := "Matthew"
         SEQ I = 0 FOR SIZE string
            output ! string[I]
             
    


Records

Occam also supports record types, which are basically variables containing concatenated primitive types. However, occam's records do not allow elements to be updated individually. That is, notations such as C's
    record.variable = 0;
are not possible. Occam requires the record data to be retrieved using its integer ordinal position, making the use of records unnecessarily complex.

Next: Procedures
Return to Index